developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 1 | From 47094ac819aba0809c899fe8ad1083b319617813 Mon Sep 17 00:00:00 2001 |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 2 | From: "Allen.Ye" <allen.ye@mediatek.com> |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 3 | Date: Thu, 8 Sep 2022 10:31:06 +0800 |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 4 | Subject: [PATCH] HAL: add get and set radio mode |
| 5 | |
| 6 | --- |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 7 | source/wifi/wifi_hal.c | 120 ++++++++++++++++++++++++++++++++++++++++- |
| 8 | 1 file changed, 119 insertions(+), 1 deletion(-) |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 9 | |
| 10 | diff --git a/source/wifi/wifi_hal.c b/source/wifi/wifi_hal.c |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 11 | index fa1af2e..9e17de6 100644 |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 12 | --- a/source/wifi/wifi_hal.c |
| 13 | +++ b/source/wifi/wifi_hal.c |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 14 | @@ -170,6 +170,15 @@ typedef enum |
| 15 | band_6 = 2, |
| 16 | } wifi_band; |
| 17 | |
| 18 | +typedef enum { |
| 19 | + WIFI_MODE_A = 0x01, |
| 20 | + WIFI_MODE_B = 0x02, |
| 21 | + WIFI_MODE_G = 0x04, |
| 22 | + WIFI_MODE_N = 0x08, |
| 23 | + WIFI_MODE_AC = 0x10, |
| 24 | + WIFI_MODE_AX = 0x20, |
| 25 | +} wifi_ieee80211_Mode; |
| 26 | + |
| 27 | #ifdef WIFI_HAL_VERSION_3 |
| 28 | |
| 29 | // Return number of elements in array |
| 30 | @@ -1696,7 +1705,63 @@ INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 31 | #endif |
| 32 | } |
| 33 | |
| 34 | -//Set the radio operating mode, and pure mode flag. |
| 35 | +INT wifi_getRadioMode(INT radioIndex, CHAR *output_string, UINT *pureMode) |
| 36 | +{ |
| 37 | + char cmd[128] = {0}; |
| 38 | + char buf[64] = {0}; |
| 39 | + char config_file[64] = {0}; |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 40 | + wifi_band band; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 41 | + |
| 42 | + WIFI_ENTRY_EXIT_DEBUG("Inside %s:%d\n",__func__, __LINE__); |
| 43 | + if(NULL == output_string || NULL == pureMode) |
| 44 | + return RETURN_ERR; |
| 45 | + |
| 46 | + // grep all of the ieee80211 protocol config set to 1 |
| 47 | + snprintf(config_file, sizeof(cmd), "%s%d.conf", CONFIG_PREFIX, radioIndex); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 48 | + snprintf(cmd, sizeof(cmd), "cat %s | grep -E\"^ieee.*=1\" | cut -d '=' -f1 | tr -d 'ieee80211'", config_file); |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 49 | + _syscmd(cmd, buf, sizeof(buf)); |
| 50 | + |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 51 | + band = wifi_index_to_band(radioIndex); |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 52 | + // puremode is a bit map |
| 53 | + *pureMode = 0; |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 54 | + if (band == band_2_4) { |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 55 | + strcat(output_string, "b,g"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 56 | + *pureMode |= WIFI_MODE_B | WIFI_MODE_G; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 57 | + if (strstr(buf, "n") != NULL) { |
| 58 | + strcat(output_string, ",n"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 59 | + *pureMode |= WIFI_MODE_N; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 60 | + } |
| 61 | + if (strstr(buf, "ax") != NULL) { |
| 62 | + strcat(output_string, ",ax"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 63 | + *pureMode |= WIFI_MODE_AX; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 64 | + } |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 65 | + } else if (band == band_5) { |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 66 | + strcat(output_string, "a"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 67 | + *pureMode |= WIFI_MODE_A; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 68 | + if (strstr(buf, "n") != NULL) { |
| 69 | + strcat(output_string, ",n"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 70 | + *pureMode |= WIFI_MODE_N; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 71 | + } |
| 72 | + if (strstr(buf, "ac") != NULL) { |
| 73 | + strcat(output_string, ",ac"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 74 | + *pureMode |= WIFI_MODE_AC; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 75 | + } |
| 76 | + if (strstr(buf, "ax") != NULL) { |
| 77 | + strcat(output_string, ",ax"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 78 | + *pureMode |= WIFI_MODE_AX; |
| 79 | + } |
| 80 | + } else if (band == band_6) { |
| 81 | + if (strstr(buf, "ax") != NULL) { |
| 82 | + strcat(output_string, "ax"); |
| 83 | + *pureMode |= WIFI_MODE_AX; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__); |
| 88 | + return RETURN_OK; |
| 89 | +} |
| 90 | + |
| 91 | +// Set the radio operating mode, and pure mode flag. |
| 92 | INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag) //RDKB |
| 93 | { |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 94 | WIFI_ENTRY_EXIT_DEBUG("Inside %s_%s_%d_%d:%d\n",__func__,channelMode,nOnlyFlag,gOnlyFlag,__LINE__); |
| 95 | @@ -1791,6 +1856,59 @@ INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 96 | return RETURN_OK; |
| 97 | } |
| 98 | |
| 99 | +// Set the radio operating mode, and pure mode flag. |
| 100 | +INT wifi_setRadioMode(INT radioIndex, CHAR *channelMode, UINT pureMode) |
| 101 | +{ |
| 102 | + int num_hostapd_support_mode = 3; // n, ac, ax |
| 103 | + struct params list[num_hostapd_support_mode]; |
| 104 | + char config_file[64] = {0}; |
| 105 | + char bandwidth[16] = {0}; |
| 106 | + int mode_check_bit = 1 << 3; // n mode |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 107 | + wifi_ieee80211_Mode mode = (wifi_ieee80211_Mode)pureMode; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 108 | + |
| 109 | + WIFI_ENTRY_EXIT_DEBUG("Inside %s_%d:%d\n", __func__, channelMode, pureMode, __LINE__); |
| 110 | + // Set radio mode |
| 111 | + list[0].name = "ieee80211n"; |
| 112 | + list[1].name = "ieee80211ac"; |
| 113 | + list[2].name = "ieee80211ax"; |
| 114 | + snprintf(config_file, sizeof(config_file), "%s%d.conf", CONFIG_PREFIX, radioIndex); |
| 115 | + |
| 116 | + // check the bit map from n to ax, and set hostapd config |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 117 | + if (mode & WIFI_MODE_N) |
| 118 | + list[0].value = "1"; |
| 119 | + else |
| 120 | + list[0].value = "0"; |
| 121 | + if (mode & WIFI_MODE_AC) |
| 122 | + list[1].value = "1"; |
| 123 | + else |
| 124 | + list[1].value = "0"; |
| 125 | + if (mode & WIFI_MODE_AX) |
| 126 | + list[2].value = "1"; |
| 127 | + else |
| 128 | + list[2].value = "0"; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 129 | + wifi_hostapdWrite(config_file, list, num_hostapd_support_mode); |
| 130 | + |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 131 | + if (channelMode == NULL || strlen(channelMode) == 0) |
| 132 | + return RETURN_OK; |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 133 | + // Set bandwidth |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 134 | + if (strstr(channelMode, "40") != NULL) |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 135 | + strcpy(bandwidth, "40MHz"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 136 | + else if (strstr(channelMode, "80") != NULL) |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 137 | + strcpy(bandwidth, "80MHz"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 138 | + else if (strstr(channelMode, "160") != NULL) |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 139 | + strcpy(bandwidth, "160MHz"); |
developer | 832578a | 2022-09-07 16:12:26 +0800 | [diff] [blame^] | 140 | + else // 11A, 11B, 11G.... |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 141 | + strcpy(bandwidth, "20MHz"); |
developer | 2fd57aa | 2022-08-17 14:43:10 +0800 | [diff] [blame] | 142 | + |
| 143 | + writeBandWidth(radioIndex, bandwidth); |
| 144 | + wifi_setRadioOperatingChannelBandwidth(radioIndex, bandwidth); |
| 145 | + |
| 146 | + wifi_reloadAp(radioIndex); |
| 147 | + WIFI_ENTRY_EXIT_DEBUG("Exiting %s:%d\n",__func__, __LINE__); |
| 148 | + |
| 149 | + return RETURN_OK; |
| 150 | +} |
| 151 | + |
| 152 | //Get the list of supported channel. eg: "1-11" |
| 153 | //The output_string is a max length 64 octet string that is allocated by the RDKB code. Implementations must ensure that strings are not longer than this. |
| 154 | INT wifi_getRadioPossibleChannels(INT radioIndex, CHAR *output_string) //RDKB |
| 155 | -- |
| 156 | 2.18.0 |
| 157 | |