diff options
Diffstat (limited to 'service/lib/common.cpp')
-rw-r--r-- | service/lib/common.cpp | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/service/lib/common.cpp b/service/lib/common.cpp deleted file mode 100644 index dd8099ba2..000000000 --- a/service/lib/common.cpp +++ /dev/null @@ -1,168 +0,0 @@ - -#include <stdlib.h> -#include <netlink/handlers.h> - -#include "wifi_hal.h" -#include "common.h" - -interface_info *getIfaceInfo(wifi_interface_handle handle) -{ - return (interface_info *)handle; -} - -wifi_handle getWifiHandle(wifi_interface_handle handle) -{ - return getIfaceInfo(handle)->handle; -} - -hal_info *getHalInfo(wifi_handle handle) -{ - return (hal_info *)handle; -} - -hal_info *getHalInfo(wifi_interface_handle handle) -{ - return getHalInfo(getWifiHandle(handle)); -} - -wifi_handle getWifiHandle(hal_info *info) -{ - return (wifi_handle)info; -} - -wifi_interface_handle getIfaceHandle(interface_info *info) -{ - return (wifi_interface_handle)info; -} - -wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg) -{ - hal_info *info = (hal_info *)handle; - - /* TODO: check for multiple handlers? */ - - if (info->num_event_cb < info->alloc_event_cb) { - info->event_cb[info->num_event_cb].nl_cmd = cmd; - info->event_cb[info->num_event_cb].vendor_id = 0; - info->event_cb[info->num_event_cb].vendor_subcmd = 0; - info->event_cb[info->num_event_cb].cb_func = func; - info->event_cb[info->num_event_cb].cb_arg = arg; - info->num_event_cb++; - ALOGI("Successfully added event handler %p for command %d", func, cmd); - return WIFI_SUCCESS; - } else { - return WIFI_ERROR_OUT_OF_MEMORY; - } -} - -wifi_error wifi_register_vendor_handler(wifi_handle handle, - uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg) -{ - hal_info *info = (hal_info *)handle; - - /* TODO: check for multiple handlers? */ - - if (info->num_event_cb < info->alloc_event_cb) { - info->event_cb[info->num_event_cb].nl_cmd = NL80211_CMD_VENDOR; - info->event_cb[info->num_event_cb].vendor_id = id; - info->event_cb[info->num_event_cb].vendor_subcmd = subcmd; - info->event_cb[info->num_event_cb].cb_func = func; - info->event_cb[info->num_event_cb].cb_arg = arg; - info->num_event_cb++; - ALOGI("Added event handler %p for vendor 0x%0x and subcmd 0x%0x", func, id, subcmd); - return WIFI_SUCCESS; - } else { - return WIFI_ERROR_OUT_OF_MEMORY; - } -} - -void wifi_unregister_handler(wifi_handle handle, int cmd) -{ - hal_info *info = (hal_info *)handle; - - if (cmd == NL80211_CMD_VENDOR) { - ALOGE("Must use wifi_unregister_vendor_handler to remove vendor handlers"); - } - - for (int i = 0; i < info->num_event_cb; i++) { - if (info->event_cb[i].nl_cmd == cmd) { - memmove(&info->event_cb[i], &info->event_cb[i+1], - (info->num_event_cb - i) * sizeof(cb_info)); - info->num_event_cb--; - ALOGI("Successfully removed event handler for command %d", cmd); - return; - } - } -} - -void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd) -{ - hal_info *info = (hal_info *)handle; - - for (int i = 0; i < info->num_event_cb; i++) { - - if (info->event_cb[i].nl_cmd == NL80211_CMD_VENDOR - && info->event_cb[i].vendor_id == id - && info->event_cb[i].vendor_subcmd == subcmd) { - - memmove(&info->event_cb[i], &info->event_cb[i+1], - (info->num_event_cb - i) * sizeof(cb_info)); - info->num_event_cb--; - ALOGI("Successfully removed event handler for vendor 0x%0x", id); - return; - } - } -} - - -wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd) -{ - hal_info *info = (hal_info *)handle; - - ALOGD("registering command %d", id); - - if (info->num_cmd < info->alloc_cmd) { - info->cmd[info->num_cmd].id = id; - info->cmd[info->num_cmd].cmd = cmd; - info->num_cmd++; - ALOGI("Successfully added command %d: %p", id, cmd); - return WIFI_SUCCESS; - } else { - return WIFI_ERROR_OUT_OF_MEMORY; - } -} - -WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id) -{ - hal_info *info = (hal_info *)handle; - - ALOGD("un-registering command %d", id); - - for (int i = 0; i < info->num_cmd; i++) { - if (info->cmd[i].id == id) { - WifiCommand *cmd = info->cmd[i].cmd; - memmove(&info->cmd[i], &info->cmd[i+1], (info->num_cmd - i) * sizeof(cmd_info)); - info->num_cmd--; - ALOGI("Successfully removed command %d: %p", id, cmd); - return cmd; - } - } - - return NULL; -} - -void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd) -{ - hal_info *info = (hal_info *)handle; - - for (int i = 0; i < info->num_cmd; i++) { - if (info->cmd[i].cmd == cmd) { - int id = info->cmd[i].id; - memmove(&info->cmd[i], &info->cmd[i+1], (info->num_cmd - i) * sizeof(cmd_info)); - info->num_cmd--; - ALOGI("Successfully removed command %d: %p", id, cmd); - return; - } - } -} - |