linuxOS_D21X/package/third-party/hostapd/0002-hostapd-Add-cardplay-optimization-code-from-zhijian.patch
2024-11-29 16:33:21 +08:00

424 lines
9.9 KiB
Diff

From 707b9debe2d32dd07e8749d3f9977e5a4cdabec6 Mon Sep 17 00:00:00 2001
From: "lv.wu" <lv.wu@artinchip.com>
Date: Wed, 27 Mar 2024 14:32:14 +0800
Subject: [PATCH] hostapd: Add cardplay optimization code from zhijian
---
hostapd/Android.mk | 7 +
hostapd/config_file.c | 367 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 373 insertions(+), 1 deletion(-)
diff --git a/hostapd/Android.mk b/hostapd/Android.mk
index bf26e41..996e0ad 100644
--- a/hostapd/Android.mk
+++ b/hostapd/Android.mk
@@ -215,6 +215,13 @@ L_CFLAGS += -DCONFIG_RSN_PREAUTH
CONFIG_L2_PACKET=y
endif
+CONFIG_HS20=y
+
+ifdef CONFIG_HS20
+NEED_AES_OMAC1=y
+CONFIG_PROXYARP=y
+endif
+
ifdef CONFIG_HS20
CONFIG_PROXYARP=y
endif
diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index b38a846..7ab4882 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -163,7 +163,6 @@ void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
}
}
-
static int hostapd_config_read_maclist(const char *fname,
struct mac_acl_entry **acl, int *num)
{
@@ -4734,6 +4733,371 @@ static int hostapd_config_fill(struct hostapd_config *conf,
return 0;
}
+#if 1 //add zj_hostapd_fill start
+#if 0 //for android sdk
+#include <linux/if.h>
+#include <dirent.h>
+#endif
+#if 1 //for linux sdk
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <dirent.h>
+#endif
+
+static void string_2_hexstring(char *in, char *out)
+{
+ int i;
+ for(i = 0; i < strlen(in); i++)
+ {
+ char tmp[8];
+ sprintf(tmp, "%02X", *(in + i));
+ memcpy(out + i * 2, tmp, strlen(tmp));
+ }
+}
+
+static int get_local_AP_mac(char *name, char* mac)
+{
+ struct ifreq tmp;
+ int sock_mac;
+ char mac_addr[30];
+ sock_mac = socket(AF_INET, SOCK_STREAM, 0);
+ if( sock_mac == -1){
+ perror("create socket fail\n");
+ return -1;
+ }
+ memset(&tmp,0,sizeof(tmp));
+ strncpy(tmp.ifr_name, name, sizeof(tmp.ifr_name)-1 );
+ if( (ioctl( sock_mac, SIOCGIFHWADDR, &tmp)) < 0 ){
+ printf("mac ioctl error\n");
+ return -1;
+ }
+ sprintf(mac_addr, "%02x%02x%02x%02x%02x%02x",
+ (unsigned char)tmp.ifr_hwaddr.sa_data[0],
+ (unsigned char)tmp.ifr_hwaddr.sa_data[1],
+ (unsigned char)tmp.ifr_hwaddr.sa_data[2],
+ (unsigned char)tmp.ifr_hwaddr.sa_data[3],
+ (unsigned char)tmp.ifr_hwaddr.sa_data[4],
+ (unsigned char)tmp.ifr_hwaddr.sa_data[5]
+ );
+
+ close(sock_mac);
+// memcpy(mac,mac_addr,strlen(mac_addr));
+ strcpy(mac, mac_addr);
+
+ return 0;
+}
+
+static int tools_exec_cmd(const char *cmd, char *out, int size)
+{
+ FILE *ptr;
+ int ret = 0;
+ char tmp[512] = {0};
+
+ if((ptr=popen(cmd, "r")) == NULL)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: tools_exec_cmd");
+ return -1;
+ }
+
+ memset(out, 0, size);
+ if(fgets(tmp, sizeof(tmp), ptr) != NULL)
+ {
+ if(strlen(out) <= size)
+ strcat(out, tmp);
+ }
+
+ pclose(ptr);
+ return 0;
+}
+
+static int get_zj_hostapd_internet(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.hostapdinternet", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 1)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static int get_zj_hostapd_flags(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.hostapdflags", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 4)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static int get_zj_hostapd_name(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.hostapdname", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 2)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static int get_zj_hostapd_Manufacturer(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.hostapdManufacturer", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 2)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static int get_zj_hostapd_Model(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.hostapdModel", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 2)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static int get_zj_hostapd_bt_MAC(char *out)
+{
+ char buffer[128];
+
+ memset(buffer, 0, sizeof(buffer));
+ if(tools_exec_cmd("getprop persist.zj.BTmac", buffer, sizeof(buffer)) < 0)
+ return -1;
+
+ if(strlen(buffer) < 6)
+ return -1;
+
+ strtok(buffer,"\n");
+ strcpy(out, buffer);
+
+ return 0;
+}
+
+static void zj_hostapd_config_fill(struct hostapd_bss_config *bss)
+{
+ char *buf = NULL;
+ char tmp[512];
+ int total = 0;
+
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill");
+
+#ifdef CONFIG_INTERWORKING
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: CONFIG_INTERWORKING on");
+#endif
+
+ bss->interworking = 1;
+ bss->access_network_type = 3;
+ bss->asra = 0;
+ bss->esr = 0;
+ bss->uesa = 0;
+ bss->venue_group = 10;
+ bss->venue_type = 3;
+ bss->venue_info_set = 1;
+
+ memset(tmp, 0, sizeof(tmp));
+ if(get_zj_hostapd_internet(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default internet val = 0\n");
+ bss->internet = 0;
+ }
+ else if(atoi(tmp) == 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: internet = 0\n");
+ bss->internet = 0;
+ }
+ else if(atoi(tmp) == 1)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: internet = 1\n");
+ bss->internet = 1;
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: internet error, use default 0\n");
+ bss->internet = 0;
+ }
+
+//fixed OUI+ subtype
+ char *oui_subtype = "00A04000";
+
+ total += strlen(oui_subtype);
+
+//flags
+ char flags[16];
+ memset(flags, 0, sizeof(flags));
+ if(get_zj_hostapd_flags(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default flags\n");
+ strcpy(flags, "00020023");
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: flags = '%s'\n", tmp);
+ sprintf(flags, "0002%s", tmp);
+ }
+
+ total += strlen(flags);
+
+//name
+ char name[32];
+ memset(name, 0, sizeof(name));
+ if(get_zj_hostapd_name(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default name\n");
+ strcpy(name, "01025A4A");
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: name = '%s'\n", tmp);
+ char hex_string[64];
+ memset(hex_string, 0, sizeof(hex_string));
+ string_2_hexstring(tmp, hex_string);
+ sprintf(name, "01%02X%s", (unsigned int)strlen(hex_string)/2, hex_string);
+ }
+
+ total += strlen(name);
+
+//Manufacturer
+ char Manufacturer[128];
+ memset(Manufacturer, 0, sizeof(Manufacturer));
+ if(get_zj_hostapd_Manufacturer(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default Manufacturer\n");
+ strcpy(Manufacturer, "02054170706C65");
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: Manufacturer = '%s'\n", tmp);
+ char hex_string[64];
+ memset(hex_string, 0, sizeof(hex_string));
+ string_2_hexstring(tmp, hex_string);
+ sprintf(Manufacturer, "02%02X%s", (unsigned int)strlen(hex_string)/2, hex_string);
+ }
+
+ total += strlen(Manufacturer);
+
+//Model
+ char Model[128];
+ memset(Model, 0, sizeof(Model));
+ if(get_zj_hostapd_Model(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default Model\n");
+ strcpy(Model, "0309446576696365312C31");
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: Model = '%s'\n", tmp);
+ char hex_string[64];
+ memset(hex_string, 0, sizeof(hex_string));
+ string_2_hexstring(tmp, hex_string);
+ sprintf(Model, "03%02X%s", (unsigned int)strlen(hex_string)/2, hex_string);
+ }
+
+ total += strlen(Model);
+
+//apple OUI
+ char *apple_OUI = "040300A040";
+
+ total += strlen(apple_OUI);
+
+//local_BT_mac
+ char local_BT_mac[32];
+ memset(local_BT_mac, 0, sizeof(local_BT_mac));
+ if(get_zj_hostapd_bt_MAC(tmp) < 0)
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: use the default local_BT_mac\n");
+ strcpy(local_BT_mac, "0606203CAE392571");
+ }
+ else
+ {
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: local_BT_mac = '%s'\n", tmp);
+ sprintf(local_BT_mac, "06%02X%s", (unsigned int)strlen(tmp)/2, tmp);
+ }
+
+ total += strlen(local_BT_mac);
+
+//local_AP_mac
+ char local_AP_mac[32];
+ memset(local_AP_mac, 0, sizeof(local_AP_mac));
+ get_local_AP_mac(bss->iface, tmp);
+ sprintf(local_AP_mac, "07%02X%s", (unsigned int)strlen(tmp)/2, tmp);
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: local_AP_mac '%s'\n", local_AP_mac);
+
+ total += strlen(local_AP_mac);
+
+ asprintf(&buf, "DD%02X%s%s%s%s%s%s%s%s", total/2, oui_subtype, flags, name, Manufacturer, Model, apple_OUI, local_BT_mac, local_AP_mac);
+
+ wpa_printf(MSG_INFO, "zj_hostapd_config_fill: '%s'\n", buf);
+
+ struct wpabuf *elems;
+ size_t len = os_strlen(buf);
+ if (len & 0x01) {
+ wpa_printf(MSG_ERROR,
+ "Invalid vendor_elements '%s'",
+ buf);
+ return;
+ }
+ len /= 2;
+ if (len == 0) {
+ wpabuf_free(bss->vendor_elements);
+ bss->vendor_elements = NULL;
+ return;
+ }
+
+ elems = wpabuf_alloc(len);
+ if (elems == NULL)
+ return;
+
+ if (hexstr2bin(buf, wpabuf_put(elems, len), len)) {
+ wpabuf_free(elems);
+ wpa_printf(MSG_ERROR,
+ "Invalid vendor_elements '%s'",
+ buf);
+ return;
+ }
+
+ wpabuf_free(bss->vendor_elements);
+ bss->vendor_elements = elems;
+}
+#endif //add zj_hostapd_fill end
/**
* hostapd_config_read - Read and parse a configuration file
@@ -4804,6 +5168,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
errors += hostapd_config_fill(conf, bss, buf, pos, line);
}
+ zj_hostapd_config_fill(conf->last_bss);
fclose(f);
for (i = 0; i < conf->num_bss; i++)
--
2.29.0