3 #include <linux/pkt_sched.h>
4 #include <netlink/object-api.h>
5 #include <netlink/handlers.h>
10 interface_info *getIfaceInfo(wifi_interface_handle handle)
12 return (interface_info *)handle;
15 wifi_handle getWifiHandle(wifi_interface_handle handle)
17 return getIfaceInfo(handle)->handle;
20 hal_info *getHalInfo(wifi_handle handle)
22 return (hal_info *)handle;
25 hal_info *getHalInfo(wifi_interface_handle handle)
27 return getHalInfo(getWifiHandle(handle));
30 wifi_handle getWifiHandle(hal_info *info)
32 return (wifi_handle)info;
35 wifi_interface_handle getIfaceHandle(interface_info *info)
37 return (wifi_interface_handle)info;
40 wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg)
42 hal_info *info = (hal_info *)handle;
44 /* TODO: check for multiple handlers? */
45 pthread_mutex_lock(&info->cb_lock);
47 wifi_error result = WIFI_ERROR_OUT_OF_MEMORY;
49 if (info->num_event_cb < info->alloc_event_cb) {
50 info->event_cb[info->num_event_cb].nl_cmd = cmd;
51 info->event_cb[info->num_event_cb].vendor_id = 0;
52 info->event_cb[info->num_event_cb].vendor_subcmd = 0;
53 info->event_cb[info->num_event_cb].cb_func = func;
54 info->event_cb[info->num_event_cb].cb_arg = arg;
55 ALOGI("Successfully added event handler %p:%p for command %d at %d",
56 arg, func, cmd, info->num_event_cb);
58 result = WIFI_SUCCESS;
61 pthread_mutex_unlock(&info->cb_lock);
65 wifi_error wifi_register_vendor_handler(wifi_handle handle,
66 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg)
68 hal_info *info = (hal_info *)handle;
70 /* TODO: check for multiple handlers? */
71 pthread_mutex_lock(&info->cb_lock);
73 wifi_error result = WIFI_ERROR_OUT_OF_MEMORY;
75 if (info->num_event_cb < info->alloc_event_cb) {
76 info->event_cb[info->num_event_cb].nl_cmd = NL80211_CMD_VENDOR;
77 info->event_cb[info->num_event_cb].vendor_id = id;
78 info->event_cb[info->num_event_cb].vendor_subcmd = subcmd;
79 info->event_cb[info->num_event_cb].cb_func = func;
80 info->event_cb[info->num_event_cb].cb_arg = arg;
81 ALOGI("Added event handler %p:%p for vendor 0x%0x and subcmd 0x%0x at %d",
82 arg, func, id, subcmd, info->num_event_cb);
84 result = WIFI_SUCCESS;
87 pthread_mutex_unlock(&info->cb_lock);
91 void wifi_unregister_handler(wifi_handle handle, int cmd)
93 hal_info *info = (hal_info *)handle;
95 if (cmd == NL80211_CMD_VENDOR) {
96 ALOGE("Must use wifi_unregister_vendor_handler to remove vendor handlers");
100 pthread_mutex_lock(&info->cb_lock);
102 for (int i = 0; i < info->num_event_cb; i++) {
103 if (info->event_cb[i].nl_cmd == cmd) {
104 ALOGI("Successfully removed event handler %p:%p for cmd = 0x%0x from %d",
105 info->event_cb[i].cb_arg, info->event_cb[i].cb_func, cmd, i);
107 memmove(&info->event_cb[i], &info->event_cb[i+1],
108 (info->num_event_cb - i - 1) * sizeof(cb_info));
109 info->num_event_cb--;
114 pthread_mutex_unlock(&info->cb_lock);
117 void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd)
119 hal_info *info = (hal_info *)handle;
121 pthread_mutex_lock(&info->cb_lock);
123 for (int i = 0; i < info->num_event_cb; i++) {
125 if (info->event_cb[i].nl_cmd == NL80211_CMD_VENDOR
126 && info->event_cb[i].vendor_id == id
127 && info->event_cb[i].vendor_subcmd == subcmd) {
128 ALOGI("Successfully removed event handler %p:%p for vendor 0x%0x, subcmd 0x%0x from %d",
129 info->event_cb[i].cb_arg, info->event_cb[i].cb_func, id, subcmd, i);
130 memmove(&info->event_cb[i], &info->event_cb[i+1],
131 (info->num_event_cb - i - 1) * sizeof(cb_info));
132 info->num_event_cb--;
137 pthread_mutex_unlock(&info->cb_lock);
141 wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd)
143 hal_info *info = (hal_info *)handle;
145 ALOGD("registering command %d", id);
147 wifi_error result = WIFI_ERROR_OUT_OF_MEMORY;
149 if (info->num_cmd < info->alloc_cmd) {
150 info->cmd[info->num_cmd].id = id;
151 info->cmd[info->num_cmd].cmd = cmd;
152 ALOGI("Successfully added command %d: %p at %d", id, cmd, info->num_cmd);
154 result = WIFI_SUCCESS;
160 WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id)
162 hal_info *info = (hal_info *)handle;
164 ALOGD("un-registering command %d", id);
166 WifiCommand *cmd = NULL;
168 for (int i = 0; i < info->num_cmd; i++) {
169 if (info->cmd[i].id == id) {
170 cmd = info->cmd[i].cmd;
171 memmove(&info->cmd[i], &info->cmd[i+1], (info->num_cmd - i) * sizeof(cmd_info));
173 ALOGI("Successfully removed command %d: %p from %d", id, cmd, i);
181 WifiCommand *wifi_get_cmd(wifi_handle handle, int id)
183 hal_info *info = (hal_info *)handle;
185 WifiCommand *cmd = NULL;
187 for (int i = 0; i < info->num_cmd; i++) {
188 if (info->cmd[i].id == id) {
189 cmd = info->cmd[i].cmd;
197 void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd)
199 hal_info *info = (hal_info *)handle;
201 for (int i = 0; i < info->num_cmd; i++) {
202 if (info->cmd[i].cmd == cmd) {
203 int id = info->cmd[i].id;
204 memmove(&info->cmd[i], &info->cmd[i+1], (info->num_cmd - i) * sizeof(cmd_info));
206 ALOGI("Successfully removed command %d: %p from %d", id, cmd, i);