Provide a shim for libqsap
authorNolen Johnson <johnsonnolen@gmail.com>
Tue, 20 Sep 2022 22:18:04 +0000 (18:18 -0400)
committerNolen Johnson <johnsonnolen@gmail.com>
Wed, 21 Sep 2022 16:57:22 +0000 (12:57 -0400)
* Android.mk because we link libqsap_sdk which is Android.mk.

Co-authored-by: Dan Pasanen <dan.pasanen@gmail.com>
Co-authored-by: Erfan Abdi <erfangplus@gmail.com>
Co-authored-by: Prema Chand Alugu <premaca@gmail.com>
Co-authored-by: Jeferson <jroliveira.oliveira301@gmail.com>
Co-authored-by: Nolen Johnson <johnsonnolen@gmail.com>
Change-Id: I97b856d1bf6d390c65cb0043e8ffe4d3d0d55d75

libqsap_shim/Android.mk [new file with mode: 0644]
libqsap_shim/libqsap_shim.c [new file with mode: 0644]

diff --git a/libqsap_shim/Android.mk b/libqsap_shim/Android.mk
new file mode 100644 (file)
index 0000000..1d1d944
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# Copyright (C) 2022 The LineageOS Project
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := libqsap_shim.c
+LOCAL_SHARED_LIBRARIES := libqsap_sdk liblog libcutils libutils
+LOCAL_C_INCLUDES := $(TOP)/system/qcom/softap/sdk
+LOCAL_MODULE := libqsapshim
+LOCAL_MODULE_TAGS := optional
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_VENDOR_MODULE := true
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libqsap_shim/libqsap_shim.c b/libqsap_shim/libqsap_shim.c
new file mode 100644 (file)
index 0000000..eaecbbd
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+   Copyright 2022, The LineageOS Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+#include "qsap_api.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <linux/wireless.h>
+#include <string.h>
+
+#include "log/log.h"
+
+// Keep in sync with system/qcom/softap/sdk/qsap_api.c
+struct Command qsap_str[eSTR_LAST] = {
+    { "wpa",                     NULL           },
+    { "accept_mac_file",         NULL           },
+    { "deny_mac_file",           NULL           },
+    { "gAPMacAddr",              "00deadbeef04" },/** AP MAC address */
+    { "gEnableApProt",           "1"            },/** protection flag in ini file */
+    { "gFixedRate",              "0"            },/** Fixed rate in ini */
+    { "gTxPowerCap",             "27"           },/** Tx power in ini */
+    { "gFragmentationThreshold", "2346"         },/** Fragmentation threshold in ini */
+    { "RTSThreshold",            "2347"         },/** RTS threshold in ini */
+    { "gAPCntryCode",            "USI"          },/** Country code in ini */
+    { "gDisableIntraBssFwd",     "0"            },/** Intra-bss forward in ini */
+    { "WmmIsEnabled",            "0"            },/** WMM */
+    { "g11dSupportEnabled",      "1"            },/** 802.11d support */
+    { "ieee80211n",              NULL           },
+    { "ctrl_interface",          NULL           },
+    { "interface",               NULL           },
+    { "eap_server",              NULL           },
+    { "gAPAutoShutOff",          "0"            },
+    { "gEnablePhyAgcListenMode",  "128"          },
+};
+
+// system/qcom/softap/sdk/qsap_api.h
+#define eERR_SET_TX_POWER (eERR_GET_AUTO_CHAN + 1)
+
+s32 wifi_qsap_set_tx_power(s32 tx_power)
+{
+#define QCSAP_IOCTL_SET_MAX_TX_POWER   (SIOCIWFIRSTPRIV + 22)
+    s32 sock;
+    s32 ret = eERR_SET_TX_POWER;
+    s8  interface[128];
+    s8  *iface;
+    s32 len = 128;
+    struct iwreq wrq;
+
+    if(NULL == (iface = qsap_get_config_value(CONFIG_FILE, &qsap_str[STR_INTERFACE], interface, (u32*)&len))) {
+        ALOGE("%s :interface error \n", __func__);
+        return ret;
+    }
+
+    /* Issue QCSAP_IOCTL_SET_MAX_TX_POWER ioctl */
+    sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+    if (sock < 0) {
+        ALOGE("%s :socket error \n", __func__);
+        return eERR_SET_TX_POWER;
+    }
+
+    strlcpy(wrq.ifr_name, iface, sizeof(wrq.ifr_name));
+    wrq.u.data.length = sizeof(s32);
+    wrq.u.data.pointer = &tx_power;
+    wrq.u.data.flags = 0;
+
+    ret = ioctl(sock, QCSAP_IOCTL_SET_MAX_TX_POWER, &wrq);
+    close(sock);
+
+    if (ret) {
+        ALOGE("%s :IOCTL set tx power failed: %d\n", __func__, ret);
+        ret = eERR_SET_TX_POWER;
+    } else {
+        ALOGD("%s :IOCTL set tx power issued\n", __func__);
+        ret = eSUCCESS;
+    }
+
+    return ret;
+}