lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /**
|
| 2 | *
|
| 3 | * @file amt_wifi_test.c
|
| 4 | * @brief
|
| 5 | * This file is part of FTM.
|
| 6 | * AMT´úÀíÓ¦Óòã
|
| 7 | *
|
| 8 | * @details
|
| 9 | * @author Tools Team.
|
| 10 | * @email
|
| 11 | * @copyright Copyright (C) 2013 Sanechips Technology Co., Ltd.
|
| 12 | * @warning
|
| 13 | * @date 2019/02/02
|
| 14 | * @version 1.1
|
| 15 | * @pre
|
| 16 | * @post
|
| 17 | *
|
| 18 | * @par
|
| 19 | * Change History :
|
| 20 | * ---------------------------------------------------------------------------
|
| 21 | * date version author description
|
| 22 | * ---------------------------------------------------------------------------
|
| 23 | * 2015/04/28 1.0 lu.xieji Create file
|
| 24 | * 2019/02/02 1.1 jiang.fenglin ÐÞ¸Ä×¢ÊÍ·½Ê½Îªdoxygen
|
| 25 | * ---------------------------------------------------------------------------
|
| 26 | *
|
| 27 | *
|
| 28 | */
|
| 29 |
|
| 30 |
|
| 31 | #include <stdlib.h>
|
| 32 | #include <stdio.h>
|
| 33 | #include <string.h>
|
| 34 | #include <fcntl.h>
|
| 35 | #include <sys/stat.h>
|
| 36 | #include "amt.h"
|
| 37 |
|
| 38 | #define MAX_CMD_BUFFER_LENGTH 256
|
| 39 | #define MAX_RECV_BUFFER_LENGTH 2048
|
| 40 |
|
| 41 | //static char g_CmdBuffer[MAX_CMD_BUFFER_LENGTH];
|
| 42 | //static char g_RecvBuffer[MAX_RECV_BUFFER_LENGTH];
|
| 43 |
|
| 44 | /**
|
| 45 | * @brief AMT²âÊÔWIFI³õʼ»¯
|
| 46 | * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
|
| 47 | * @note
|
| 48 | * @see
|
| 49 | */
|
| 50 | int Amt_Wifi_Init(void)
|
| 51 | {
|
| 52 | return 0;
|
| 53 | }
|
| 54 |
|
| 55 | int wifi_ioctl_handle(int cmd)
|
| 56 | {
|
| 57 | int fd = -1;
|
| 58 | int ret = 0;
|
| 59 | fd = open("/dev/wifi_device", O_RDWR);
|
| 60 | if (fd < 0)
|
| 61 | return -1;
|
| 62 | ret = ioctl(fd, cmd);
|
| 63 | if (ret < 0)
|
| 64 | printf("ioctl wifi_device err:%d\n", ret);
|
| 65 | close(fd);
|
| 66 | return ret;
|
| 67 | }
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 | /**
|
| 72 | * @brief AMT´¦ÀíWIFIÏûÏ¢º¯Êý
|
| 73 | * @param[in] msg_id FID
|
| 74 | * @param[in] msg_buf ½ÓÊÕÊý¾Ýbuffer
|
| 75 | * @param[in] msg_len ½ÓÊÕÊý¾Ýbuffer³¤¶È
|
| 76 | * @return ³É¹¦·µ»Ø0, ʧ°Ü·µ»Ø-1
|
| 77 | * @note
|
| 78 | * @see
|
| 79 | */
|
| 80 | int Amt_Wifi_ProcessMsg(unsigned int msg_id, unsigned char* msg_buf, unsigned int msg_len)
|
| 81 | {
|
| 82 | char*pCmdBuffer = malloc(MAX_CMD_BUFFER_LENGTH);
|
| 83 | if (pCmdBuffer == NULL)
|
| 84 | {
|
| 85 | AmtPrintf(AMT_ERROR "%s: malloc pCmdBuffer failure.\n", __FUNCTION__);
|
| 86 | return -1;
|
| 87 | }
|
| 88 | char*pRecvBuffer = malloc(MAX_RECV_BUFFER_LENGTH);
|
| 89 | if (pRecvBuffer == NULL)
|
| 90 | {
|
| 91 | AmtPrintf(AMT_ERROR "%s: malloc pRecvBuffer failure.\n", __FUNCTION__);
|
| 92 | free(pCmdBuffer);
|
| 93 | return -1;
|
| 94 | }
|
| 95 | memcpy(pCmdBuffer, msg_buf, msg_len);
|
| 96 | pCmdBuffer[msg_len] = '\0';
|
| 97 |
|
| 98 | memset(pRecvBuffer, 0, MAX_RECV_BUFFER_LENGTH);
|
| 99 |
|
| 100 | AmtPrintf(AMT_INFO "%s: cmd=%s.\n", __FUNCTION__, pCmdBuffer);
|
| 101 |
|
| 102 | // sv6158 load firmware
|
| 103 | if ((strcmp(pCmdBuffer, "insmod ./lib/modules/3.4.110-rt140/kernel/drivers/net/wireless/ssv6x5x/ssv6x5x.ko stacfgpath=/etc/firmware/ssv6x5x-wifi.cfg") == 0)||
|
| 104 | (strcmp(pCmdBuffer, "insmod ./lib/modules/3.4.110-rt140/kernel/drivers/net/wireless/ssv6x5x/prealloc/ssv6xxx_prealloc_skb.ko") == 0)||
|
| 105 | (strcmp(pCmdBuffer, "insmod ./lib/modules/3.4.110-rt140/kernel/drivers/net/wireless/ssv6x5x/ssv6x5x_host/ssv6x5x.ko stacfgpath=/etc/firmware/ssv6x5x-wifi.cfg") == 0))
|
| 106 | {
|
| 107 | static int load_flag = 0;
|
| 108 | AmtPrintf(AMT_INFO "%s: recv insmod cmd=%s.\n", __FUNCTION__, pCmdBuffer);
|
| 109 | if(load_flag == 0)
|
| 110 | {
|
| 111 | int ret = wifi_ioctl_handle(1);
|
| 112 | load_flag = 1;
|
| 113 | if(ret < 0)
|
| 114 | {
|
| 115 | AmtPrintf(AMT_ERROR "%s: load sv6158 firmware fail! ret=%d.\n", __FUNCTION__, ret);
|
| 116 | free(pCmdBuffer);
|
| 117 | free(pRecvBuffer);
|
| 118 | return -1;
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | if (Amt_CreateResponse(msg_id, &ret, sizeof(ret)) == -1)
|
| 123 | {
|
| 124 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 125 | }
|
| 126 | else
|
| 127 | {
|
| 128 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 129 | }
|
| 130 |
|
| 131 | free(pCmdBuffer);
|
| 132 | free(pRecvBuffer);
|
| 133 |
|
| 134 | return 0;
|
| 135 | }
|
| 136 |
|
| 137 | }
|
| 138 | else
|
| 139 | {
|
| 140 | free(pCmdBuffer);
|
| 141 | free(pRecvBuffer);
|
| 142 | return 0;
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 |
|
| 147 | int read_len = Amt_ExecuteCmd(pCmdBuffer, pRecvBuffer, MAX_RECV_BUFFER_LENGTH);
|
| 148 |
|
| 149 | if (read_len > 0)
|
| 150 | {
|
| 151 | // Ç¿ÖÆÔö¼Ó½áÊø·û
|
| 152 | pRecvBuffer[MAX_RECV_BUFFER_LENGTH - 1] = '\0';
|
| 153 |
|
| 154 | // Broadcom
|
| 155 | if (strcmp(pCmdBuffer, "wl counters") == 0)
|
| 156 | {
|
| 157 | char pRxStr[] = "pktengrxdmcast";
|
| 158 | char *ptr = strstr(pRecvBuffer, pRxStr);
|
| 159 |
|
| 160 | if (ptr != NULL)
|
| 161 | {
|
| 162 | int packetsNum = 0;
|
| 163 | sscanf(ptr, "%*[^ ]%d", &packetsNum);
|
| 164 | memcpy(pRecvBuffer, &packetsNum, sizeof(packetsNum));
|
| 165 | read_len = sizeof(packetsNum);
|
| 166 | }
|
| 167 | else
|
| 168 | {
|
| 169 | AmtPrintf(AMT_ERROR "%s: Can not find \"%s\".\n", __FUNCTION__, pRxStr);
|
| 170 | free(pCmdBuffer);
|
| 171 | free(pRecvBuffer);
|
| 172 | return -1;
|
| 173 | }
|
| 174 | }
|
| 175 |
|
| 176 | if (Amt_CreateResponse(msg_id, (unsigned char*)pRecvBuffer, read_len) == -1)
|
| 177 | {
|
| 178 | AmtPrintf(AMT_ERROR "%s: Send data failure.\n", __FUNCTION__);
|
| 179 | }
|
| 180 | else
|
| 181 | {
|
| 182 | AmtPrintf(AMT_INFO "%s: Send data success.\n", __FUNCTION__);
|
| 183 | }
|
| 184 | }
|
| 185 | else
|
| 186 | {
|
| 187 | AmtPrintf(AMT_INFO "%s: no return.\n", __FUNCTION__);
|
| 188 | }
|
| 189 | free(pCmdBuffer);
|
| 190 | free(pRecvBuffer);
|
| 191 | return 0;
|
| 192 | }
|
| 193 |
|
| 194 |
|