.. | .. |
---|
29 | 29 | #include <log/log.h> |
---|
30 | 30 | #include <cutils/properties.h> |
---|
31 | 31 | #include <pthread.h> |
---|
| 32 | +#include <regex.h> |
---|
32 | 33 | |
---|
33 | 34 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
---|
34 | 35 | #define UEVENT_MSG_LEN 1024 |
---|
.. | .. |
---|
98 | 99 | {"ssv", {"libwifi-hal-ssv.so" }}, |
---|
99 | 100 | {"sprd", {"libwifi-hal-sprd.so" }}, |
---|
100 | 101 | {"aic", {"libwifi-hal-aic.so" }}, |
---|
| 102 | + {"seekwave", {"libwifi-hal-skw.so" }}, |
---|
| 103 | + {"seekwave_lite",{"libwifi-hal-skw.so" }}, |
---|
101 | 104 | }; |
---|
102 | 105 | |
---|
103 | 106 | static const struct info_t libbt_name[] = { |
---|
.. | .. |
---|
107 | 110 | {"qualcomm", {"libbt-qualcomm.so"}}, |
---|
108 | 111 | {"sprd", {"libbt-sprd.so" }}, |
---|
109 | 112 | {"aic", {"libbt-aic.so" }}, |
---|
| 113 | + {"seekwave", {"libbt-skw.so" }}, |
---|
| 114 | + {"seekwave_lite", {"libbt-skw.so" }}, |
---|
110 | 115 | }; |
---|
111 | 116 | |
---|
112 | 117 | static const struct info_t wifi_drv_para[] = { |
---|
113 | 118 | {"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", |
---|
120 | 121 | 0, |
---|
121 | 122 | } |
---|
122 | 123 | }, |
---|
.. | .. |
---|
126 | 127 | } |
---|
127 | 128 | }, |
---|
128 | 129 | {"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", |
---|
134 | 131 | 0, |
---|
135 | 132 | } |
---|
136 | 133 | }, |
---|
.. | .. |
---|
162 | 159 | {0x13030, "ssv6x5x", "ssv6x5x", "ssv6x5x", "ssv", 0}, |
---|
163 | 160 | {0x10000, "uwe5622", "sprdwl_ng", "sprdwl_ng", "sprd", 1}, |
---|
164 | 161 | {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}, |
---|
165 | 164 | }; |
---|
166 | 165 | |
---|
167 | 166 | /* default select invalid if get wifi_hardware_info failed */ |
---|
.. | .. |
---|
253 | 252 | p++; |
---|
254 | 253 | strncpy(val, dst, p -dst); |
---|
255 | 254 | 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(®, pattern, REG_EXTENDED); |
---|
| 320 | + while (regexec(®, 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(®); |
---|
| 338 | + |
---|
256 | 339 | return 0; |
---|
257 | 340 | } |
---|
258 | 341 | |
---|
.. | .. |
---|
783 | 866 | property_set(MODULE_BT_SUPPORT_PROP, wifiinfo->bt_support ? "1" : "0"); |
---|
784 | 867 | } |
---|
785 | 868 | } |
---|
| 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 | + |
---|
786 | 875 | return wifiinfo; |
---|
787 | 876 | } |
---|
788 | 877 | |
---|
.. | .. |
---|
812 | 901 | |
---|
813 | 902 | const char *get_driver_module_arg(void) |
---|
814 | 903 | { |
---|
815 | | - static char module_arg[256] = {0}; |
---|
| 904 | + static char module_arg[1024] = {0}; |
---|
816 | 905 | struct wifi_hardware_info *hwinfo = get_wifi_hardware_info(); |
---|
817 | | - const char *para; |
---|
| 906 | + char buffer[1024]; |
---|
818 | 907 | int n = 0; |
---|
819 | 908 | for (int i = 0; i < ARRAY_SIZE(wifi_drv_para); i++) { |
---|
820 | 909 | 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]); |
---|
831 | 912 | } |
---|
| 913 | + buffer[n - 2] = '\0'; |
---|
| 914 | + str_expand(buffer, module_arg); |
---|
832 | 915 | return module_arg; |
---|
833 | 916 | } |
---|
834 | 917 | } |
---|