common.h revision 115bcffc16c53e9552c09a6792666c52a633b4f2
1 2#include "wifi_hal.h" 3 4#ifndef __WIFI_HAL_COMMON_H__ 5#define __WIFI_HAL_COMMON_H__ 6 7#define LOG_TAG "WifiHAL" 8 9#include <utils/Log.h> 10#include "nl80211_copy.h" 11#include "sync.h" 12 13#define SOCKET_BUFFER_SIZE (32768U) 14#define RECV_BUF_SIZE (4096) 15#define DEFAULT_EVENT_CB_SIZE (64) 16#define DEFAULT_CMD_SIZE (64) 17 18/* 19 Vendor OUI - This is a unique identifier that identifies organization. Lets 20 code Android specific functions with Google OUI; although vendors can do more 21 with their own OUI's as well. 22 */ 23 24const uint32_t GOOGLE_OUI = 0x001A11; 25/* TODO: define vendor OUI here */ 26 27 28/* 29 This enum defines ranges for various commands; commands themselves 30 can be defined in respective feature headers; i.e. find gscan command 31 definitions in gscan.cpp 32 */ 33 34typedef enum { 35 /* don't use 0 as a valid subcommand */ 36 VENDOR_NL80211_SUBCMD_UNSPECIFIED, 37 38 /* define all vendor startup commands between 0x0 and 0x0FFF */ 39 VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001, 40 VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF, 41 42 /* define all GScan related commands between 0x1000 and 0x10FF */ 43 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000, 44 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF, 45 46 /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */ 47 ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100, 48 ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF, 49 50 /* define all RTT related commands between 0x1100 and 0x11FF */ 51 ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100, 52 ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF, 53 54 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200, 55 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF, 56 57 /* This is reserved for future usage */ 58 59} ANDROID_VENDOR_SUB_COMMAND; 60 61typedef enum { 62 BRCM_RESERVED1, 63 BRCM_RESERVED2, 64 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS , 65 GSCAN_EVENT_HOTLIST_RESULTS, 66 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE, 67 GSCAN_EVENT_FULL_SCAN_RESULTS, 68 RTT_EVENT_COMPLETE 69 70} WIFI_EVENT; 71 72typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events); 73 74class WifiCommand; 75 76typedef struct { 77 int nl_cmd; 78 uint32_t vendor_id; 79 int vendor_subcmd; 80 nl_recvmsg_msg_cb_t cb_func; 81 void *cb_arg; 82} cb_info; 83 84typedef struct { 85 wifi_request_id id; 86 WifiCommand *cmd; 87} cmd_info; 88 89typedef struct { 90 wifi_handle handle; // handle to wifi data 91 char name[8+1]; // interface name + trailing null 92 int id; // id to use when talking to driver 93} interface_info; 94 95typedef struct { 96 97 struct nl_sock *cmd_sock; // command socket object 98 struct nl_sock *event_sock; // event socket object 99 int nl80211_family_id; // family id for 80211 driver 100 101 bool in_event_loop; // Indicates that event loop is active 102 bool clean_up; // Indication to clean up the socket 103 104 wifi_internal_event_handler event_handler; // default event handler 105 wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler 106 107 cb_info *event_cb; // event callbacks 108 int num_event_cb; // number of event callbacks 109 int alloc_event_cb; // number of allocated callback objects 110 pthread_mutex_t cb_lock; // mutex for the event_cb access 111 112 cmd_info *cmd; // Outstanding commands 113 int num_cmd; // number of commands 114 int alloc_cmd; // number of commands allocated 115 116 interface_info **interfaces; // array of interfaces 117 int num_interfaces; // number of interfaces 118 119 120 // add other details 121} hal_info; 122 123wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg); 124wifi_error wifi_register_vendor_handler(wifi_handle handle, 125 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg); 126 127void wifi_unregister_handler(wifi_handle handle, int cmd); 128void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd); 129 130wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd); 131WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id); 132WifiCommand *wifi_get_cmd(wifi_handle handle, int id); 133void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd); 134 135interface_info *getIfaceInfo(wifi_interface_handle); 136wifi_handle getWifiHandle(wifi_interface_handle handle); 137hal_info *getHalInfo(wifi_handle handle); 138hal_info *getHalInfo(wifi_interface_handle handle); 139wifi_handle getWifiHandle(hal_info *info); 140wifi_interface_handle getIfaceHandle(interface_info *info); 141 142 143// some common macros 144 145#define min(x, y) ((x) < (y) ? (x) : (y)) 146#define max(x, y) ((x) > (y) ? (x) : (y)) 147 148#endif 149 150