[7885] wlbt :ND Offload's Implementation.
[GitHub/LineageOS/android_hardware_samsung_slsi_scsc_wifibt_wifi_hal.git] / common.cpp
index 1a724251baf0aa96a80355bf14bd24ff97c6a766..b28a815076b0c06c6e389017245232460e0f813f 100755 (executable)
@@ -1,10 +1,24 @@
 
-#include <stdlib.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <linux/rtnetlink.h>
+#include <netpacket/packet.h>
+#include <linux/filter.h>
+#include <linux/errqueue.h>
+
+#include <linux/pkt_sched.h>
 #include <netlink/object-api.h>
+#include <netlink/netlink.h>
+#include <netlink/socket.h>
 #include <netlink/handlers.h>
 
 #include "wifi_hal.h"
 #include "common.h"
+#include "cpp_bindings.h"
 
 interface_info *getIfaceInfo(wifi_interface_handle handle)
 {
@@ -51,8 +65,9 @@ wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_
         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;
+        /*
         ALOGI("Successfully added event handler %p:%p for command %d at %d",
-                arg, func, cmd, info->num_event_cb);
+                arg, func, cmd, info->num_event_cb);*/
         info->num_event_cb++;
         result = WIFI_SUCCESS;
     }
@@ -69,19 +84,20 @@ wifi_error wifi_register_vendor_handler(wifi_handle handle,
 //ALOGD("GSCAN register handle wifi_register_vendor_handler %p", handle);
     /* TODO: check for multiple handlers? */
     pthread_mutex_lock(&info->cb_lock);
-        ALOGI("Added event handler %p", info);
+    //ALOGI("Added event handler %p", info);
 
     wifi_error result = WIFI_ERROR_OUT_OF_MEMORY;
 
-       //    ALOGD("register_vendor_handler: handle = %p", handle);
+    //    ALOGD("register_vendor_handler: handle = %p", handle);
     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;
+        /*
         ALOGI("Added event handler %p:%p for vendor 0x%0x and subcmd 0x%0x at %d",
-                arg, func, id, subcmd, info->num_event_cb);
+                arg, func, id, subcmd, info->num_event_cb);*/
         info->num_event_cb++;
         result = WIFI_SUCCESS;
     }
@@ -103,8 +119,9 @@ void wifi_unregister_handler(wifi_handle handle, int cmd)
 
     for (int i = 0; i < info->num_event_cb; i++) {
         if (info->event_cb[i].nl_cmd == cmd) {
+            /*
             ALOGI("Successfully removed event handler %p:%p for cmd = 0x%0x from %d",
-                    info->event_cb[i].cb_arg, info->event_cb[i].cb_func, cmd, i);
+                    info->event_cb[i].cb_arg, info->event_cb[i].cb_func, cmd, i);*/
 
             memmove(&info->event_cb[i], &info->event_cb[i+1],
                 (info->num_event_cb - i - 1) * sizeof(cb_info));
@@ -127,8 +144,9 @@ void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd)
         if (info->event_cb[i].nl_cmd == NL80211_CMD_VENDOR
                 && info->event_cb[i].vendor_id == id
                 && info->event_cb[i].vendor_subcmd == subcmd) {
+            /*
             ALOGI("Successfully removed event handler %p:%p for vendor 0x%0x, subcmd 0x%0x from %d",
-                    info->event_cb[i].cb_arg, info->event_cb[i].cb_func, id, subcmd, i);
+                    info->event_cb[i].cb_arg, info->event_cb[i].cb_func, id, subcmd, i);*/
             memmove(&info->event_cb[i], &info->event_cb[i+1],
                 (info->num_event_cb - i - 1) * sizeof(cb_info));
             info->num_event_cb--;
@@ -144,14 +162,14 @@ wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd)
 {
     hal_info *info = (hal_info *)handle;
 
-    ALOGD("registering command %d", id);
+    //ALOGD("registering command %d", id);
 
     wifi_error result = WIFI_ERROR_OUT_OF_MEMORY;
 
     if (info->num_cmd < info->alloc_cmd) {
         info->cmd[info->num_cmd].id   = id;
         info->cmd[info->num_cmd].cmd  = cmd;
-        ALOGI("Successfully added command %d: %p at %d", id, cmd, info->num_cmd);
+        //ALOGI("Successfully added command %d: %p at %d", id, cmd, info->num_cmd);
         info->num_cmd++;
         result = WIFI_SUCCESS;
     }
@@ -163,7 +181,7 @@ WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id)
 {
     hal_info *info = (hal_info *)handle;
 
-    ALOGD("un-registering command %d", id);
+    //ALOGD("un-registering command %d", id);
 
     WifiCommand *cmd = NULL;
 
@@ -172,7 +190,7 @@ WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id)
             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 from %d", id, cmd, i);
+            //ALOGI("Successfully removed command %d: %p from %d", id, cmd, i);
             break;
         }
     }
@@ -205,8 +223,23 @@ void wifi_unregister_cmd(wifi_handle handle, WifiCommand *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 from %d", id, cmd, i);
+            //ALOGI("Successfully removed command %d: %p from %d", id, cmd, i);
             break;
         }
     }
 }
+
+wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface)
+{
+       wifi_handle handle = getWifiHandle(iface);
+
+       WifiCommand *cmd = wifi_unregister_cmd(handle, id);
+       //ALOGD("Cancel WifiCommand = %p", cmd);
+       if (cmd) {
+               cmd->cancel();
+               cmd->releaseRef();
+               return WIFI_SUCCESS;
+       }
+
+    return WIFI_ERROR_INVALID_ARGS;
+}