rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | *WIFI driver kernel module insmod file for wmt dynamic loader |
| 3 | */ |
| 4 | #include <stdlib.h> |
| 5 | #include <stdio.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <errno.h> |
| 8 | #include <unistd.h> |
| 9 | #include <string.h> |
| 10 | #include <cutils/log.h> |
| 11 | #include <cutils/misc.h> |
| 12 | #include <linux/module.h> |
| 13 | //For directory operation |
| 14 | #include <dirent.h> |
| 15 | |
| 16 | extern int load_wifi_module(int chip_id); |
| 17 | extern int init_module(void *, unsigned long, const char *); |
| 18 | extern int delete_module(const char *, unsigned int); |
| 19 | |
| 20 | static char DRIVER_MODULE_PATH[50] = "/system/lib/modules/wlan_"; |
| 21 | static char DRIVER_MODULE_ARG[50] = ""; |
| 22 | #ifndef WIFI_DRIVER_MODULE_ARG |
| 23 | #define WIFI_DRIVER_MODULE_ARG "" |
| 24 | #endif |
| 25 | |
| 26 | //insmod |
| 27 | static int insmod(const char *filename, const char *args) |
| 28 | { |
| 29 | void *module; |
| 30 | unsigned int size; |
| 31 | int ret; |
| 32 | |
| 33 | module = load_file(filename, &size); |
| 34 | if (!module) |
| 35 | return -1; |
| 36 | |
| 37 | ret = init_module(module, size, args); |
| 38 | |
| 39 | free(module); |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static int rmmod(const char *modname) |
| 45 | { |
| 46 | int ret = -1; |
| 47 | int maxtry = 10; |
| 48 | |
| 49 | while (maxtry-- > 0) { |
| 50 | ret = delete_module(modname, O_NONBLOCK | O_EXCL); |
| 51 | if (ret < 0 && errno == EAGAIN) |
| 52 | usleep(500000); |
| 53 | else |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | if (ret != 0) |
| 58 | ALOGD("Unable to unload driver module \"%s\": %s\n", |
| 59 | modname, strerror(errno)); |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | int load_wifi_module(int chip_id) |
| 64 | { |
| 65 | int ret=-1; |
| 66 | |
| 67 | if(chip_id == 0x6630){ |
| 68 | //insert 6630 driver |
| 69 | if(0 == insmod("/system/lib/modules/mtk_wmt_wifi.ko", DRIVER_MODULE_ARG)){ |
| 70 | ret = 0; |
| 71 | printf("Success to insmod wmt wifi module\n"); |
| 72 | }else |
| 73 | printf("Fail to insmod wmt wifi module\n"); |
| 74 | |
| 75 | if(0 == insmod("/system/lib/modules/wlan_mt6630.ko", DRIVER_MODULE_ARG)){ |
| 76 | ret = 0; |
| 77 | printf("Success to insmod wlan module\n"); |
| 78 | }else |
| 79 | printf("Fail to insmod wlan module\n"); |
| 80 | } |
| 81 | else if(chip_id == 0x6628){ |
| 82 | //insert 6628 driver |
| 83 | if(0 == insmod("/system/lib/modules/mtk_wmt_wifi.ko", DRIVER_MODULE_ARG)){ |
| 84 | ret = 0; |
| 85 | printf("Success to insmod wmt wifi module\n"); |
| 86 | }else |
| 87 | printf("Fail to insmod wmt wifi module\n"); |
| 88 | |
| 89 | if(0 == insmod("/system/lib/modules/wlan_mt6628.ko", DRIVER_MODULE_ARG)){ |
| 90 | ret = 0; |
| 91 | printf("Success to insmod wlan module\n"); |
| 92 | }else |
| 93 | printf("Fail to insmod wlan module\n"); |
| 94 | } |
| 95 | else if(chip_id == 0x6620){ |
| 96 | //insert 6620 driver |
| 97 | }else { //for soc chip, same naming |
| 98 | //insert wmt_wifi => for temp naming |
| 99 | if(0 == insmod("/system/lib/modules/mtk_wmt_wifi_soc.ko", DRIVER_MODULE_ARG)){ |
| 100 | ret = 0; |
| 101 | printf("Success to insmod wmt wifi module\n"); |
| 102 | }else |
| 103 | printf("Fail to insmod wmt wifi module\n"); |
| 104 | |
| 105 | //insert wifi => for temp naming |
| 106 | if(0 == insmod("/system/lib/modules/wlan_mt.ko", DRIVER_MODULE_ARG)){ |
| 107 | ret = 0; |
| 108 | printf("Success to insmod the %s\n", DRIVER_MODULE_PATH); |
| 109 | }else |
| 110 | printf("Fail to insmod the %s\n", DRIVER_MODULE_PATH); |
| 111 | } |
| 112 | return ret; |
| 113 | } |