common.h revision 71cd80b3a0a1d019090f0dc022fce785ded3883e
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
23const 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
33typedef 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    ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
54    ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END   = 0x12FF,
55
56    /* This is reserved for future usage */
57
58} ANDROID_VENDOR_SUB_COMMAND;
59
60typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
61
62class WifiCommand;
63
64typedef struct {
65    int nl_cmd;
66    uint32_t vendor_id;
67    int vendor_subcmd;
68    nl_recvmsg_msg_cb_t cb_func;
69    void *cb_arg;
70} cb_info;
71
72typedef struct {
73    wifi_request_id id;
74    WifiCommand *cmd;
75} cmd_info;
76
77typedef struct {
78    wifi_handle handle;                             // handle to wifi data
79    char name[8+1];                                 // interface name + trailing null
80    int  id;                                        // id to use when talking to driver
81} interface_info;
82
83typedef struct {
84
85    struct nl_sock *cmd_sock;                       // command socket object
86    struct nl_sock *event_sock;                     // event socket object
87    int nl80211_family_id;                          // family id for 80211 driver
88
89    bool in_event_loop;                             // Indicates that event loop is active
90    bool clean_up;                                  // Indication to clean up the socket
91
92    wifi_internal_event_handler event_handler;      // default event handler
93    wifi_cleaned_up_handler cleaned_up_handler;     // socket cleaned up handler
94
95    cb_info *event_cb;                              // event callbacks
96    int num_event_cb;                               // number of event callbacks
97    int alloc_event_cb;                             // number of allocated callback objects
98
99    cmd_info *cmd;                                  // Outstanding commands
100    int num_cmd;                                    // number of commands
101    int alloc_cmd;                                  // number of commands allocated
102
103    interface_info **interfaces;                    // array of interfaces
104    int num_interfaces;                             // number of interfaces
105
106    // add other details
107} hal_info;
108
109wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg);
110wifi_error wifi_register_vendor_handler(wifi_handle handle,
111            uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg);
112
113void wifi_unregister_handler(wifi_handle handle, int cmd);
114void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd);
115
116wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
117WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
118void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
119
120interface_info *getIfaceInfo(wifi_interface_handle);
121wifi_handle getWifiHandle(wifi_interface_handle handle);
122hal_info *getHalInfo(wifi_handle handle);
123hal_info *getHalInfo(wifi_interface_handle handle);
124wifi_handle getWifiHandle(hal_info *info);
125wifi_interface_handle getIfaceHandle(interface_info *info);
126
127
128// some common macros
129
130#define min(x, y)       ((x) < (y) ? (x) : (y))
131#define max(x, y)       ((x) > (y) ? (x) : (y))
132
133#endif
134
135