lin
2025-08-21 57113df3a0e2be01232281fad9a5f2c060567981
android/hardware/aw/wireless/hwinfo/libhwinfo.c
....@@ -29,6 +29,7 @@
2929 #include <log/log.h>
3030 #include <cutils/properties.h>
3131 #include <pthread.h>
32
+#include <regex.h>
3233
3334 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
3435 #define UEVENT_MSG_LEN 1024
....@@ -98,6 +99,8 @@
9899 {"ssv", {"libwifi-hal-ssv.so" }},
99100 {"sprd", {"libwifi-hal-sprd.so" }},
100101 {"aic", {"libwifi-hal-aic.so" }},
102
+ {"seekwave", {"libwifi-hal-skw.so" }},
103
+ {"seekwave_lite",{"libwifi-hal-skw.so" }},
101104 };
102105
103106 static const struct info_t libbt_name[] = {
....@@ -107,16 +110,14 @@
107110 {"qualcomm", {"libbt-qualcomm.so"}},
108111 {"sprd", {"libbt-sprd.so" }},
109112 {"aic", {"libbt-aic.so" }},
113
+ {"seekwave", {"libbt-skw.so" }},
114
+ {"seekwave_lite", {"libbt-skw.so" }},
110115 };
111116
112117 static const struct info_t wifi_drv_para[] = {
113118 {"broadcom",
114
- {"nvram_path=/vendor/etc/firmware/nvram_",
115
- "$module_name",
116
- ".txt ",
117
- "config_path=/vendor/etc/firmware/config_",
118
- "$module_name",
119
- ".txt",
119
+ {"nvram_path=/vendor/etc/firmware/nvram_${module_name}.txt",
120
+ "config_path=/vendor/etc/firmware/config_${module_name}.txt",
120121 0,
121122 }
122123 },
....@@ -126,11 +127,7 @@
126127 }
127128 },
128129 {"ssv",
129
- {"stacfgpath=/vendor/etc/firmware/",
130
- "$module_name",
131
- "/",
132
- "$module_name",
133
- "-wifi.cfg",
130
+ {"stacfgpath=/vendor/etc/firmware/${module_name}/${module_name}-wifi.cfg",
134131 0,
135132 }
136133 },
....@@ -162,6 +159,8 @@
162159 {0x13030, "ssv6x5x", "ssv6x5x", "ssv6x5x", "ssv", 0},
163160 {0x10000, "uwe5622", "sprdwl_ng", "sprdwl_ng", "sprd", 1},
164161 {0x10145, "aic8800", "aic8800_fdrv","aic8800_fdrv","aic", 1},
162
+ {0x10000, "skw", "skw", "skw", "seekwave", 1},
163
+ {0x16621, "skw6160_lite", "swt6621s_wifi", "swt6621s_wifi", "seekwave_lite", 1},
165164 };
166165
167166 /* default select invalid if get wifi_hardware_info failed */
....@@ -253,6 +252,90 @@
253252 p++;
254253 strncpy(val, dst, p -dst);
255254 val[p - dst] = 0;
255
+ return 0;
256
+}
257
+
258
+// You must free the result if result is non-NULL.
259
+static char *str_replace(char *orig, char *rep, char *with)
260
+{
261
+ char *result; // the return string
262
+ char *ins; // the next insert point
263
+ char *tmp; // varies
264
+ int len_rep; // length of rep (the string to remove)
265
+ int len_with; // length of with (the string to replace rep with)
266
+ int len_front; // distance between rep and end of last rep
267
+ int count; // number of replacements
268
+
269
+ // sanity checks and initialization
270
+ if (!orig || !rep)
271
+ return NULL;
272
+ len_rep = strlen(rep);
273
+ if (len_rep == 0)
274
+ return NULL; // empty rep causes infinite loop during count
275
+ if (!with)
276
+ with = "";
277
+ len_with = strlen(with);
278
+
279
+ // count the number of replacements needed
280
+ ins = orig;
281
+ for (count = 0; (tmp = strstr(ins, rep)); ++count) {
282
+ ins = tmp + len_rep;
283
+ }
284
+
285
+ tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
286
+
287
+ if (!result)
288
+ return NULL;
289
+
290
+ // first time through the loop, all the variable are set correctly
291
+ // from here on,
292
+ // tmp points to the end of the result string
293
+ // ins points to the next occurrence of rep in orig
294
+ // orig points to the remainder of orig after "end of rep"
295
+ while (count--) {
296
+ ins = strstr(orig, rep);
297
+ len_front = ins - orig;
298
+ tmp = strncpy(tmp, orig, len_front) + len_front;
299
+ tmp = strcpy(tmp, with) + len_with;
300
+ orig += len_front + len_rep; // move to next "end of rep"
301
+ }
302
+ strcpy(tmp, orig);
303
+ return result;
304
+}
305
+
306
+static int str_expand(char *text, char *expand)
307
+{
308
+ static const char *pattern = "\\$\\{[^}]+\\}";
309
+ regex_t reg;
310
+ const size_t nmatch = 1;
311
+ int i, j, status;
312
+ regmatch_t pmatch[1];
313
+ char matchstr[32];
314
+ char env_name[32];
315
+ char *env_val = NULL;
316
+ char *orig = text;
317
+ char *out;
318
+
319
+ status = regcomp(&reg, pattern, REG_EXTENDED);
320
+ while (regexec(&reg, orig, nmatch, pmatch, 0) == 0) {
321
+ memcpy(matchstr, orig + pmatch[0].rm_so, pmatch[0].rm_eo - pmatch[0].rm_so);
322
+ matchstr[pmatch[0].rm_eo - pmatch[0].rm_so] = 0;
323
+
324
+ memcpy(env_name, orig + pmatch[0].rm_so + 2, pmatch[0].rm_eo - pmatch[0].rm_so - 3);
325
+ env_name[pmatch[0].rm_eo - pmatch[0].rm_so - 3] = 0;
326
+
327
+ env_val = getenv(env_name);
328
+ out = str_replace(orig, matchstr, env_val);
329
+
330
+ if (out) {
331
+ memcpy(expand, out, strlen(out));
332
+ expand[strlen(out)] = 0;
333
+ free(out);
334
+ orig = expand;
335
+ }
336
+ }
337
+ regfree(&reg);
338
+
256339 return 0;
257340 }
258341
....@@ -783,6 +866,12 @@
783866 property_set(MODULE_BT_SUPPORT_PROP, wifiinfo->bt_support ? "1" : "0");
784867 }
785868 }
869
+
870
+ for (i = 0; i < ARRAY_SIZE(matchtab); i++) {
871
+ if (matchtab[i].type == TYPE_PCHAR)
872
+ setenv(matchtab[i].keyname, (char *)(*(ADDR_T *)((ADDR_T)wifiinfo + matchtab[i].offset)), 1);
873
+ }
874
+
786875 return wifiinfo;
787876 }
788877
....@@ -812,23 +901,17 @@
812901
813902 const char *get_driver_module_arg(void)
814903 {
815
- static char module_arg[256] = {0};
904
+ static char module_arg[1024] = {0};
816905 struct wifi_hardware_info *hwinfo = get_wifi_hardware_info();
817
- const char *para;
906
+ char buffer[1024];
818907 int n = 0;
819908 for (int i = 0; i < ARRAY_SIZE(wifi_drv_para); i++) {
820909 if (strncmp(hwinfo->vendor_name, wifi_drv_para[i].vendor, strlen(hwinfo->vendor_name)) == 0) {
821
- for (int j = 0; (j < INFO_SESSION_MAX) && ((para = wifi_drv_para[i].info[j]) != NULL); j++) {
822
- if (*para == '$') {
823
- for (int k = 0; k < ARRAY_SIZE(matchtab); k++) {
824
- if (strncmp(para + 1, matchtab[k].keyname, strlen(matchtab[k].keyname)) == 0) {
825
- para = (const char *)(*(ADDR_T *)((ADDR_T)hwinfo + matchtab[k].offset));
826
- break;
827
- }
828
- }
829
- }
830
- n += sprintf(&module_arg[n], "%s", para);
910
+ for (int j = 0; (j < INFO_SESSION_MAX) && wifi_drv_para[i].info[j] != NULL; j++) {
911
+ n += sprintf(&buffer[n], "%s ", wifi_drv_para[i].info[j]);
831912 }
913
+ buffer[n - 2] = '\0';
914
+ str_expand(buffer, module_arg);
832915 return module_arg;
833916 }
834917 }