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