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