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 #define DOT11_OUI_LEN 3 18 19 /* 20 Vendor OUI - This is a unique identifier that identifies organization. Lets 21 code Android specific functions with Google OUI; although vendors can do more 22 with their own OUI's as well. 23 */ 24 25 const uint32_t GOOGLE_OUI = 0x001A11; 26 /* TODO: define vendor OUI here */ 27 28 29 /* 30 This enum defines ranges for various commands; commands themselves 31 can be defined in respective feature headers; i.e. find gscan command 32 definitions in gscan.cpp 33 */ 34 35 typedef enum { 36 /* don't use 0 as a valid subcommand */ 37 VENDOR_NL80211_SUBCMD_UNSPECIFIED, 38 39 /* define all vendor startup commands between 0x0 and 0x0FFF */ 40 VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001, 41 VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF, 42 43 /* define all GScan related commands between 0x1000 and 0x10FF */ 44 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000, 45 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF, 46 47 /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */ 48 ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100, 49 ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF, 50 51 /* define all RTT related commands between 0x1100 and 0x11FF */ 52 ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100, 53 ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF, 54 55 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200, 56 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF, 57 58 /* This is reserved for future usage */ 59 60 } ANDROID_VENDOR_SUB_COMMAND; 61 62 typedef enum { 63 64 GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START, 65 66 GSCAN_SUBCMD_SET_CONFIG, /* 0x1001 */ 67 68 GSCAN_SUBCMD_SET_SCAN_CONFIG, /* 0x1002 */ 69 GSCAN_SUBCMD_ENABLE_GSCAN, /* 0x1003 */ 70 GSCAN_SUBCMD_GET_SCAN_RESULTS, /* 0x1004 */ 71 GSCAN_SUBCMD_SCAN_RESULTS, /* 0x1005 */ 72 73 GSCAN_SUBCMD_SET_HOTLIST, /* 0x1006 */ 74 75 GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG, /* 0x1007 */ 76 GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS, /* 0x1008 */ 77 GSCAN_SUBCMD_GET_CHANNEL_LIST, /* 0x1009 */ 78 79 WIFI_SUBCMD_GET_FEATURE_SET, /* 0x100A */ 80 WIFI_SUBCMD_GET_FEATURE_SET_MATRIX, /* 0x100B */ 81 WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI, /* 0x100C */ 82 WIFI_SUBCMD_NODFS_SET, /* 0x100D */ 83 84 /* Add more sub commands here */ 85 86 GSCAN_SUBCMD_MAX /* 0x100D */ 87 88 } WIFI_SUB_COMMAND; 89 90 typedef enum { 91 BRCM_RESERVED1, 92 BRCM_RESERVED2, 93 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS , 94 GSCAN_EVENT_HOTLIST_RESULTS_FOUND, 95 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE, 96 GSCAN_EVENT_FULL_SCAN_RESULTS, 97 RTT_EVENT_COMPLETE, 98 GSCAN_EVENT_COMPLETE_SCAN, 99 GSCAN_EVENT_HOTLIST_RESULTS_LOST 100 } WIFI_EVENT; 101 102 typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events); 103 104 class WifiCommand; 105 106 typedef struct { 107 int nl_cmd; 108 uint32_t vendor_id; 109 int vendor_subcmd; 110 nl_recvmsg_msg_cb_t cb_func; 111 void *cb_arg; 112 } cb_info; 113 114 typedef struct { 115 wifi_request_id id; 116 WifiCommand *cmd; 117 } cmd_info; 118 119 typedef struct { 120 wifi_handle handle; // handle to wifi data 121 char name[8+1]; // interface name + trailing null 122 int id; // id to use when talking to driver 123 } interface_info; 124 125 typedef struct { 126 127 struct nl_sock *cmd_sock; // command socket object 128 struct nl_sock *event_sock; // event socket object 129 int nl80211_family_id; // family id for 80211 driver 130 131 bool in_event_loop; // Indicates that event loop is active 132 bool clean_up; // Indication to clean up the socket 133 134 wifi_internal_event_handler event_handler; // default event handler 135 wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler 136 137 cb_info *event_cb; // event callbacks 138 int num_event_cb; // number of event callbacks 139 int alloc_event_cb; // number of allocated callback objects 140 pthread_mutex_t cb_lock; // mutex for the event_cb access 141 142 cmd_info *cmd; // Outstanding commands 143 int num_cmd; // number of commands 144 int alloc_cmd; // number of commands allocated 145 146 interface_info **interfaces; // array of interfaces 147 int num_interfaces; // number of interfaces 148 149 150 // add other details 151 } hal_info; 152 153 wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg); 154 wifi_error wifi_register_vendor_handler(wifi_handle handle, 155 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg); 156 157 void wifi_unregister_handler(wifi_handle handle, int cmd); 158 void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd); 159 160 wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd); 161 WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id); 162 WifiCommand *wifi_get_cmd(wifi_handle handle, int id); 163 void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd); 164 165 interface_info *getIfaceInfo(wifi_interface_handle); 166 wifi_handle getWifiHandle(wifi_interface_handle handle); 167 hal_info *getHalInfo(wifi_handle handle); 168 hal_info *getHalInfo(wifi_interface_handle handle); 169 wifi_handle getWifiHandle(hal_info *info); 170 wifi_interface_handle getIfaceHandle(interface_info *info); 171 172 173 // some common macros 174 175 #define min(x, y) ((x) < (y) ? (x) : (y)) 176 #define max(x, y) ((x) > (y) ? (x) : (y)) 177 178 #endif 179 180