KDDI Fx0 hackathon / SNICInterface_Tweet
Committer:
komoritan
Date:
Tue Feb 10 12:26:31 2015 +0000
Revision:
0:edaa24c1f5cd
Debug Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 0:edaa24c1f5cd 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
komoritan 0:edaa24c1f5cd 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART.
komoritan 0:edaa24c1f5cd 3 *
komoritan 0:edaa24c1f5cd 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
komoritan 0:edaa24c1f5cd 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
komoritan 0:edaa24c1f5cd 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
komoritan 0:edaa24c1f5cd 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
komoritan 0:edaa24c1f5cd 8 * furnished to do so, subject to the following conditions:
komoritan 0:edaa24c1f5cd 9 *
komoritan 0:edaa24c1f5cd 10 * The above copyright notice and this permission notice shall be included in all copies or
komoritan 0:edaa24c1f5cd 11 * substantial portions of the Software.
komoritan 0:edaa24c1f5cd 12 *
komoritan 0:edaa24c1f5cd 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
komoritan 0:edaa24c1f5cd 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
komoritan 0:edaa24c1f5cd 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
komoritan 0:edaa24c1f5cd 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
komoritan 0:edaa24c1f5cd 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
komoritan 0:edaa24c1f5cd 18 */
komoritan 0:edaa24c1f5cd 19 #include "SNIC_WifiInterface.h"
komoritan 0:edaa24c1f5cd 20 #include "SNIC_UartMsgUtil.h"
komoritan 0:edaa24c1f5cd 21
komoritan 0:edaa24c1f5cd 22 #define UART_CONNECT_BUF_SIZE 512
komoritan 0:edaa24c1f5cd 23 unsigned char gCONNECT_BUF[UART_CONNECT_BUF_SIZE];
komoritan 0:edaa24c1f5cd 24
komoritan 0:edaa24c1f5cd 25 C_SNIC_WifiInterface::C_SNIC_WifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud)
komoritan 0:edaa24c1f5cd 26 {
komoritan 0:edaa24c1f5cd 27 mUART_tx = tx;
komoritan 0:edaa24c1f5cd 28 mUART_rx = rx;
komoritan 0:edaa24c1f5cd 29 mUART_cts = cts;
komoritan 0:edaa24c1f5cd 30 mUART_rts = rts;;
komoritan 0:edaa24c1f5cd 31 mUART_baud = baud;
komoritan 0:edaa24c1f5cd 32 mModuleReset = reset;
komoritan 0:edaa24c1f5cd 33 }
komoritan 0:edaa24c1f5cd 34
komoritan 0:edaa24c1f5cd 35 C_SNIC_WifiInterface::~C_SNIC_WifiInterface()
komoritan 0:edaa24c1f5cd 36 {
komoritan 0:edaa24c1f5cd 37 }
komoritan 0:edaa24c1f5cd 38
komoritan 0:edaa24c1f5cd 39 int C_SNIC_WifiInterface::init()
komoritan 0:edaa24c1f5cd 40 {
komoritan 0:edaa24c1f5cd 41 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 42 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 43
komoritan 0:edaa24c1f5cd 44 /* Initialize UART */
komoritan 0:edaa24c1f5cd 45 snic_core_p->initUart( mUART_tx, mUART_rx, mUART_baud );
komoritan 0:edaa24c1f5cd 46
komoritan 0:edaa24c1f5cd 47 /* Module reset */
komoritan 0:edaa24c1f5cd 48 snic_core_p->resetModule( mModuleReset );
komoritan 0:edaa24c1f5cd 49
komoritan 0:edaa24c1f5cd 50 wait(1);
komoritan 0:edaa24c1f5cd 51 /* Initialize SNIC API */
komoritan 0:edaa24c1f5cd 52 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 53 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 54 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 55 {
komoritan 0:edaa24c1f5cd 56 DEBUG_PRINT("snic_init payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 57 return -1;
komoritan 0:edaa24c1f5cd 58 }
komoritan 0:edaa24c1f5cd 59
komoritan 0:edaa24c1f5cd 60 C_SNIC_Core::tagSNIC_INIT_REQ_T req;
komoritan 0:edaa24c1f5cd 61 // Make request
komoritan 0:edaa24c1f5cd 62 req.cmd_sid = UART_CMD_SID_SNIC_INIT_REQ;
komoritan 0:edaa24c1f5cd 63 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 64 req.buf_size[0] = 0x08;
komoritan 0:edaa24c1f5cd 65 req.buf_size[1] = 0x00;
komoritan 0:edaa24c1f5cd 66
komoritan 0:edaa24c1f5cd 67 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 68 unsigned int command_len;
komoritan 0:edaa24c1f5cd 69 // Preparation of command
komoritan 0:edaa24c1f5cd 70 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 71 , sizeof(C_SNIC_Core::tagSNIC_INIT_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 72
komoritan 0:edaa24c1f5cd 73 // Send uart command request
komoritan 0:edaa24c1f5cd 74 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 75
komoritan 0:edaa24c1f5cd 76 int ret;
komoritan 0:edaa24c1f5cd 77 // Wait UART response
komoritan 0:edaa24c1f5cd 78 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 79 if( ret != 0 )
komoritan 0:edaa24c1f5cd 80 {
komoritan 0:edaa24c1f5cd 81 DEBUG_PRINT( "snic_init failed\r\n" );
komoritan 0:edaa24c1f5cd 82 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 83 return -1;
komoritan 0:edaa24c1f5cd 84 }
komoritan 0:edaa24c1f5cd 85
komoritan 0:edaa24c1f5cd 86 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 87 {
komoritan 0:edaa24c1f5cd 88 DEBUG_PRINT("snic_init status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 89 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 90 return -1;
komoritan 0:edaa24c1f5cd 91 }
komoritan 0:edaa24c1f5cd 92 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 93
komoritan 0:edaa24c1f5cd 94 return ret;
komoritan 0:edaa24c1f5cd 95 }
komoritan 0:edaa24c1f5cd 96
komoritan 0:edaa24c1f5cd 97 int C_SNIC_WifiInterface::getFWVersion( unsigned char *version_p )
komoritan 0:edaa24c1f5cd 98 {
komoritan 0:edaa24c1f5cd 99 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 100 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 101
komoritan 0:edaa24c1f5cd 102 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 103 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 104 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 105 {
komoritan 0:edaa24c1f5cd 106 DEBUG_PRINT("getFWVersion payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 107 return -1;
komoritan 0:edaa24c1f5cd 108 }
komoritan 0:edaa24c1f5cd 109
komoritan 0:edaa24c1f5cd 110 C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T req;
komoritan 0:edaa24c1f5cd 111 // Make request
komoritan 0:edaa24c1f5cd 112 req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ;
komoritan 0:edaa24c1f5cd 113 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 114
komoritan 0:edaa24c1f5cd 115 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 116 unsigned int command_len;
komoritan 0:edaa24c1f5cd 117 // Preparation of command
komoritan 0:edaa24c1f5cd 118 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 119 , sizeof(C_SNIC_Core::tagGEN_FW_VER_GET_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 120
komoritan 0:edaa24c1f5cd 121 int ret;
komoritan 0:edaa24c1f5cd 122
komoritan 0:edaa24c1f5cd 123 // Send uart command request
komoritan 0:edaa24c1f5cd 124 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 125
komoritan 0:edaa24c1f5cd 126 // Wait UART response
komoritan 0:edaa24c1f5cd 127 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 128 if( ret != 0 )
komoritan 0:edaa24c1f5cd 129 {
komoritan 0:edaa24c1f5cd 130 DEBUG_PRINT( "getFWversion failed\r\n" );
komoritan 0:edaa24c1f5cd 131 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 132 return -1;
komoritan 0:edaa24c1f5cd 133 }
komoritan 0:edaa24c1f5cd 134
komoritan 0:edaa24c1f5cd 135 if( uartCmdMgr_p->getCommandStatus() == 0 )
komoritan 0:edaa24c1f5cd 136 {
komoritan 0:edaa24c1f5cd 137 unsigned char version_len = payload_buf_p->buf[3];
komoritan 0:edaa24c1f5cd 138 memcpy( version_p, &payload_buf_p->buf[4], version_len );
komoritan 0:edaa24c1f5cd 139 }
komoritan 0:edaa24c1f5cd 140 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 141 return 0;
komoritan 0:edaa24c1f5cd 142 }
komoritan 0:edaa24c1f5cd 143
komoritan 0:edaa24c1f5cd 144 int C_SNIC_WifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type
komoritan 0:edaa24c1f5cd 145 , const char *sec_key_p, unsigned char sec_key_len)
komoritan 0:edaa24c1f5cd 146 {
komoritan 0:edaa24c1f5cd 147 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 148 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 149
komoritan 0:edaa24c1f5cd 150 // Parameter check(SSID)
komoritan 0:edaa24c1f5cd 151 if( (ssid_p == NULL) || (ssid_len == 0) )
komoritan 0:edaa24c1f5cd 152 {
komoritan 0:edaa24c1f5cd 153 DEBUG_PRINT( "connect failed [ parameter NG:SSID ]\r\n" );
komoritan 0:edaa24c1f5cd 154 return -1;
komoritan 0:edaa24c1f5cd 155 }
komoritan 0:edaa24c1f5cd 156
komoritan 0:edaa24c1f5cd 157 // Parameter check(Security key)
komoritan 0:edaa24c1f5cd 158 if( (sec_type != e_SEC_OPEN) && ( (sec_key_len == 0) || (sec_key_p == NULL) ) )
komoritan 0:edaa24c1f5cd 159 {
komoritan 0:edaa24c1f5cd 160 DEBUG_PRINT( "connect failed [ parameter NG:Security key ]\r\n" );
komoritan 0:edaa24c1f5cd 161 return -1;
komoritan 0:edaa24c1f5cd 162 }
komoritan 0:edaa24c1f5cd 163
komoritan 0:edaa24c1f5cd 164 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 165 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 166 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 167 {
komoritan 0:edaa24c1f5cd 168 DEBUG_PRINT("connect payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 169 return -1;
komoritan 0:edaa24c1f5cd 170 }
komoritan 0:edaa24c1f5cd 171
komoritan 0:edaa24c1f5cd 172 unsigned char *buf = &gCONNECT_BUF[0];
komoritan 0:edaa24c1f5cd 173 unsigned int buf_len = 0;
komoritan 0:edaa24c1f5cd 174 unsigned int command_len;
komoritan 0:edaa24c1f5cd 175
komoritan 0:edaa24c1f5cd 176 memset( buf, 0, UART_CONNECT_BUF_SIZE );
komoritan 0:edaa24c1f5cd 177 // Make request
komoritan 0:edaa24c1f5cd 178 buf[0] = UART_CMD_SID_WIFI_JOIN_REQ;
komoritan 0:edaa24c1f5cd 179 buf_len++;
komoritan 0:edaa24c1f5cd 180 buf[1] = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 181 buf_len++;
komoritan 0:edaa24c1f5cd 182 // SSID
komoritan 0:edaa24c1f5cd 183 memcpy( &buf[2], ssid_p, ssid_len );
komoritan 0:edaa24c1f5cd 184 buf_len += ssid_len;
komoritan 0:edaa24c1f5cd 185 buf_len++;
komoritan 0:edaa24c1f5cd 186
komoritan 0:edaa24c1f5cd 187 // Security mode
komoritan 0:edaa24c1f5cd 188 buf[ buf_len ] = (unsigned char)sec_type;
komoritan 0:edaa24c1f5cd 189 buf_len++;
komoritan 0:edaa24c1f5cd 190
komoritan 0:edaa24c1f5cd 191 // Security key
komoritan 0:edaa24c1f5cd 192 if( sec_type != e_SEC_OPEN )
komoritan 0:edaa24c1f5cd 193 {
komoritan 0:edaa24c1f5cd 194 buf[ buf_len ] = sec_key_len;
komoritan 0:edaa24c1f5cd 195 buf_len++;
komoritan 0:edaa24c1f5cd 196 if( sec_key_len > 0 )
komoritan 0:edaa24c1f5cd 197 {
komoritan 0:edaa24c1f5cd 198 memcpy( &buf[buf_len], sec_key_p, sec_key_len );
komoritan 0:edaa24c1f5cd 199 buf_len += sec_key_len;
komoritan 0:edaa24c1f5cd 200 }
komoritan 0:edaa24c1f5cd 201 }
komoritan 0:edaa24c1f5cd 202
komoritan 0:edaa24c1f5cd 203 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 204 // Preparation of command
komoritan 0:edaa24c1f5cd 205 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf
komoritan 0:edaa24c1f5cd 206 , buf_len, payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 207
komoritan 0:edaa24c1f5cd 208 // Send uart command request
komoritan 0:edaa24c1f5cd 209 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 210
komoritan 0:edaa24c1f5cd 211 int ret;
komoritan 0:edaa24c1f5cd 212 // Wait UART response
komoritan 0:edaa24c1f5cd 213 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 214 if(uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_WIFI_ERR_ALREADY_JOINED)
komoritan 0:edaa24c1f5cd 215 {
komoritan 0:edaa24c1f5cd 216 DEBUG_PRINT( "Already connected\r\n" );
komoritan 0:edaa24c1f5cd 217 }
komoritan 0:edaa24c1f5cd 218 else
komoritan 0:edaa24c1f5cd 219 {
komoritan 0:edaa24c1f5cd 220 if( ret != 0 )
komoritan 0:edaa24c1f5cd 221 {
komoritan 0:edaa24c1f5cd 222 DEBUG_PRINT( "join failed\r\n" );
komoritan 0:edaa24c1f5cd 223 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 224 return -1;
komoritan 0:edaa24c1f5cd 225 }
komoritan 0:edaa24c1f5cd 226 }
komoritan 0:edaa24c1f5cd 227
komoritan 0:edaa24c1f5cd 228 if(uartCmdMgr_p->getCommandStatus() != 0)
komoritan 0:edaa24c1f5cd 229 {
komoritan 0:edaa24c1f5cd 230 DEBUG_PRINT("join status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 231 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 232 return -1;
komoritan 0:edaa24c1f5cd 233 }
komoritan 0:edaa24c1f5cd 234 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 235
komoritan 0:edaa24c1f5cd 236 return ret;
komoritan 0:edaa24c1f5cd 237 }
komoritan 0:edaa24c1f5cd 238
komoritan 0:edaa24c1f5cd 239 int C_SNIC_WifiInterface::disconnect()
komoritan 0:edaa24c1f5cd 240 {
komoritan 0:edaa24c1f5cd 241 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 242 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 243
komoritan 0:edaa24c1f5cd 244 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 245 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 246 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 247 {
komoritan 0:edaa24c1f5cd 248 DEBUG_PRINT("disconnect payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 249 return -1;
komoritan 0:edaa24c1f5cd 250 }
komoritan 0:edaa24c1f5cd 251
komoritan 0:edaa24c1f5cd 252 C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T req;
komoritan 0:edaa24c1f5cd 253 // Make request
komoritan 0:edaa24c1f5cd 254 req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ;
komoritan 0:edaa24c1f5cd 255 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 256
komoritan 0:edaa24c1f5cd 257 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 258 unsigned int command_len;
komoritan 0:edaa24c1f5cd 259 // Preparation of command
komoritan 0:edaa24c1f5cd 260 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 261 , sizeof(C_SNIC_Core::tagWIFI_DISCONNECT_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 262
komoritan 0:edaa24c1f5cd 263 // Send uart command request
komoritan 0:edaa24c1f5cd 264 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 265
komoritan 0:edaa24c1f5cd 266 int ret;
komoritan 0:edaa24c1f5cd 267 // Wait UART response
komoritan 0:edaa24c1f5cd 268 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 269 if( ret != 0 )
komoritan 0:edaa24c1f5cd 270 {
komoritan 0:edaa24c1f5cd 271 DEBUG_PRINT( "disconnect failed\r\n" );
komoritan 0:edaa24c1f5cd 272 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 273 return -1;
komoritan 0:edaa24c1f5cd 274 }
komoritan 0:edaa24c1f5cd 275
komoritan 0:edaa24c1f5cd 276 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 277 {
komoritan 0:edaa24c1f5cd 278 DEBUG_PRINT("disconnect status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 279 ret = -1;
komoritan 0:edaa24c1f5cd 280 }
komoritan 0:edaa24c1f5cd 281 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 282 return ret;
komoritan 0:edaa24c1f5cd 283 }
komoritan 0:edaa24c1f5cd 284
komoritan 0:edaa24c1f5cd 285 int C_SNIC_WifiInterface::scan( const char *ssid_p, unsigned char *bssid_p
komoritan 0:edaa24c1f5cd 286 , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) )
komoritan 0:edaa24c1f5cd 287 {
komoritan 0:edaa24c1f5cd 288 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 289 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 290
komoritan 0:edaa24c1f5cd 291 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 292 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 293 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 294 {
komoritan 0:edaa24c1f5cd 295 DEBUG_PRINT("scan payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 296 return -1;
komoritan 0:edaa24c1f5cd 297 }
komoritan 0:edaa24c1f5cd 298
komoritan 0:edaa24c1f5cd 299 C_SNIC_Core::tagWIFI_SCAN_REQ_T req;
komoritan 0:edaa24c1f5cd 300 unsigned int buf_len = 0;
komoritan 0:edaa24c1f5cd 301
komoritan 0:edaa24c1f5cd 302 memset( &req, 0, sizeof(C_SNIC_Core::tagWIFI_SCAN_REQ_T) );
komoritan 0:edaa24c1f5cd 303 // Make request
komoritan 0:edaa24c1f5cd 304 req.cmd_sid = UART_CMD_SID_WIFI_SCAN_REQ;
komoritan 0:edaa24c1f5cd 305 buf_len++;
komoritan 0:edaa24c1f5cd 306 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 307 buf_len++;
komoritan 0:edaa24c1f5cd 308
komoritan 0:edaa24c1f5cd 309 // Set scan type(Active scan)
komoritan 0:edaa24c1f5cd 310 req.scan_type = 0;
komoritan 0:edaa24c1f5cd 311 buf_len++;
komoritan 0:edaa24c1f5cd 312 // Set bss type(any)
komoritan 0:edaa24c1f5cd 313 req.bss_type = 2;
komoritan 0:edaa24c1f5cd 314 buf_len++;
komoritan 0:edaa24c1f5cd 315 // Set BSSID
komoritan 0:edaa24c1f5cd 316 if( bssid_p != NULL )
komoritan 0:edaa24c1f5cd 317 {
komoritan 0:edaa24c1f5cd 318 memcpy( req.bssid, bssid_p, BSSID_MAC_LENTH );
komoritan 0:edaa24c1f5cd 319 }
komoritan 0:edaa24c1f5cd 320 buf_len += BSSID_MAC_LENTH;
komoritan 0:edaa24c1f5cd 321 // Set channel list(0)
komoritan 0:edaa24c1f5cd 322 req.chan_list = 0;
komoritan 0:edaa24c1f5cd 323 buf_len++;
komoritan 0:edaa24c1f5cd 324 //Set SSID
komoritan 0:edaa24c1f5cd 325 if( ssid_p != NULL )
komoritan 0:edaa24c1f5cd 326 {
komoritan 0:edaa24c1f5cd 327 strcpy( (char *)req.ssid, ssid_p );
komoritan 0:edaa24c1f5cd 328 buf_len += strlen(ssid_p);
komoritan 0:edaa24c1f5cd 329 }
komoritan 0:edaa24c1f5cd 330 buf_len++;
komoritan 0:edaa24c1f5cd 331
komoritan 0:edaa24c1f5cd 332 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 333 unsigned int command_len;
komoritan 0:edaa24c1f5cd 334 // Preparation of command
komoritan 0:edaa24c1f5cd 335 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 336 , buf_len, payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 337
komoritan 0:edaa24c1f5cd 338 // Set scan result callback
komoritan 0:edaa24c1f5cd 339 uartCmdMgr_p->setScanResultHandler( result_handler_p );
komoritan 0:edaa24c1f5cd 340
komoritan 0:edaa24c1f5cd 341 // Send uart command request
komoritan 0:edaa24c1f5cd 342 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 343
komoritan 0:edaa24c1f5cd 344 int ret;
komoritan 0:edaa24c1f5cd 345 // Wait UART response
komoritan 0:edaa24c1f5cd 346 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 347 DEBUG_PRINT( "scan wait:%d\r\n", ret );
komoritan 0:edaa24c1f5cd 348 if( ret != 0 )
komoritan 0:edaa24c1f5cd 349 {
komoritan 0:edaa24c1f5cd 350 DEBUG_PRINT( "scan failed\r\n" );
komoritan 0:edaa24c1f5cd 351 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 352 return -1;
komoritan 0:edaa24c1f5cd 353 }
komoritan 0:edaa24c1f5cd 354
komoritan 0:edaa24c1f5cd 355 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 356 {
komoritan 0:edaa24c1f5cd 357 DEBUG_PRINT("scan status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 358 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 359 return -1;
komoritan 0:edaa24c1f5cd 360 }
komoritan 0:edaa24c1f5cd 361
komoritan 0:edaa24c1f5cd 362 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 363
komoritan 0:edaa24c1f5cd 364 return ret;
komoritan 0:edaa24c1f5cd 365 }
komoritan 0:edaa24c1f5cd 366
komoritan 0:edaa24c1f5cd 367 int C_SNIC_WifiInterface::wifi_on( const char *country_p )
komoritan 0:edaa24c1f5cd 368 {
komoritan 0:edaa24c1f5cd 369 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 370 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 371
komoritan 0:edaa24c1f5cd 372 // Parameter check
komoritan 0:edaa24c1f5cd 373 if( country_p == NULL )
komoritan 0:edaa24c1f5cd 374 {
komoritan 0:edaa24c1f5cd 375 DEBUG_PRINT("wifi_on parameter error\r\n");
komoritan 0:edaa24c1f5cd 376 return -1;
komoritan 0:edaa24c1f5cd 377 }
komoritan 0:edaa24c1f5cd 378
komoritan 0:edaa24c1f5cd 379 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 380 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 381 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 382 {
komoritan 0:edaa24c1f5cd 383 DEBUG_PRINT("wifi_on payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 384 return -1;
komoritan 0:edaa24c1f5cd 385 }
komoritan 0:edaa24c1f5cd 386
komoritan 0:edaa24c1f5cd 387 C_SNIC_Core::tagWIFI_ON_REQ_T req;
komoritan 0:edaa24c1f5cd 388 // Make request
komoritan 0:edaa24c1f5cd 389 req.cmd_sid = UART_CMD_SID_WIFI_ON_REQ;
komoritan 0:edaa24c1f5cd 390 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 391 memcpy( req.country, country_p, COUNTRYC_CODE_LENTH );
komoritan 0:edaa24c1f5cd 392
komoritan 0:edaa24c1f5cd 393 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 394 unsigned int command_len;
komoritan 0:edaa24c1f5cd 395 // Preparation of command
komoritan 0:edaa24c1f5cd 396 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 397 , sizeof(C_SNIC_Core::tagWIFI_ON_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 398
komoritan 0:edaa24c1f5cd 399 // Send uart command request
komoritan 0:edaa24c1f5cd 400 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 401
komoritan 0:edaa24c1f5cd 402 int ret;
komoritan 0:edaa24c1f5cd 403 // Wait UART response
komoritan 0:edaa24c1f5cd 404 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 405 if( ret != 0 )
komoritan 0:edaa24c1f5cd 406 {
komoritan 0:edaa24c1f5cd 407 DEBUG_PRINT( "wifi_on failed\r\n" );
komoritan 0:edaa24c1f5cd 408 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 409 return -1;
komoritan 0:edaa24c1f5cd 410 }
komoritan 0:edaa24c1f5cd 411
komoritan 0:edaa24c1f5cd 412 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 413 {
komoritan 0:edaa24c1f5cd 414 DEBUG_PRINT("wifi_on status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 415 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 416 return -1;
komoritan 0:edaa24c1f5cd 417 }
komoritan 0:edaa24c1f5cd 418 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 419
komoritan 0:edaa24c1f5cd 420 return ret;
komoritan 0:edaa24c1f5cd 421 }
komoritan 0:edaa24c1f5cd 422
komoritan 0:edaa24c1f5cd 423 int C_SNIC_WifiInterface::wifi_off()
komoritan 0:edaa24c1f5cd 424 {
komoritan 0:edaa24c1f5cd 425 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 426 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 427
komoritan 0:edaa24c1f5cd 428 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 429 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 430 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 431 {
komoritan 0:edaa24c1f5cd 432 DEBUG_PRINT("wifi_off payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 433 return -1;
komoritan 0:edaa24c1f5cd 434 }
komoritan 0:edaa24c1f5cd 435
komoritan 0:edaa24c1f5cd 436 C_SNIC_Core::tagWIFI_OFF_REQ_T req;
komoritan 0:edaa24c1f5cd 437 // Make request
komoritan 0:edaa24c1f5cd 438 req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ;
komoritan 0:edaa24c1f5cd 439 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 440
komoritan 0:edaa24c1f5cd 441 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 442 unsigned int command_len;
komoritan 0:edaa24c1f5cd 443 // Preparation of command
komoritan 0:edaa24c1f5cd 444 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 445 , sizeof(C_SNIC_Core::tagWIFI_OFF_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 446
komoritan 0:edaa24c1f5cd 447 // Send uart command request
komoritan 0:edaa24c1f5cd 448 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 449
komoritan 0:edaa24c1f5cd 450 int ret;
komoritan 0:edaa24c1f5cd 451 // Wait UART response
komoritan 0:edaa24c1f5cd 452 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 453 if( ret != 0 )
komoritan 0:edaa24c1f5cd 454 {
komoritan 0:edaa24c1f5cd 455 DEBUG_PRINT( "wifi_off failed\r\n" );
komoritan 0:edaa24c1f5cd 456 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 457 return -1;
komoritan 0:edaa24c1f5cd 458 }
komoritan 0:edaa24c1f5cd 459
komoritan 0:edaa24c1f5cd 460 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 461 {
komoritan 0:edaa24c1f5cd 462 DEBUG_PRINT("wifi_off status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 463 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 464 return -1;
komoritan 0:edaa24c1f5cd 465 }
komoritan 0:edaa24c1f5cd 466 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 467
komoritan 0:edaa24c1f5cd 468 return ret;
komoritan 0:edaa24c1f5cd 469 }
komoritan 0:edaa24c1f5cd 470
komoritan 0:edaa24c1f5cd 471 int C_SNIC_WifiInterface::getRssi( signed char *rssi_p )
komoritan 0:edaa24c1f5cd 472 {
komoritan 0:edaa24c1f5cd 473 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 474 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 475 if( rssi_p == NULL )
komoritan 0:edaa24c1f5cd 476 {
komoritan 0:edaa24c1f5cd 477 DEBUG_PRINT("getRssi parameter error\r\n");
komoritan 0:edaa24c1f5cd 478 return -1;
komoritan 0:edaa24c1f5cd 479 }
komoritan 0:edaa24c1f5cd 480
komoritan 0:edaa24c1f5cd 481 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 482 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 483 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 484 {
komoritan 0:edaa24c1f5cd 485 DEBUG_PRINT("getRssi payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 486 return -1;
komoritan 0:edaa24c1f5cd 487 }
komoritan 0:edaa24c1f5cd 488
komoritan 0:edaa24c1f5cd 489 C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T req;
komoritan 0:edaa24c1f5cd 490
komoritan 0:edaa24c1f5cd 491 // Make request
komoritan 0:edaa24c1f5cd 492 req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ;
komoritan 0:edaa24c1f5cd 493 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 494
komoritan 0:edaa24c1f5cd 495 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 496 unsigned int command_len;
komoritan 0:edaa24c1f5cd 497 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 498 , sizeof(C_SNIC_Core::tagWIFI_GET_STA_RSSI_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 499
komoritan 0:edaa24c1f5cd 500 int ret;
komoritan 0:edaa24c1f5cd 501 // Send uart command request
komoritan 0:edaa24c1f5cd 502 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 503
komoritan 0:edaa24c1f5cd 504 // Wait UART response
komoritan 0:edaa24c1f5cd 505 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 506 if( ret != 0 )
komoritan 0:edaa24c1f5cd 507 {
komoritan 0:edaa24c1f5cd 508 DEBUG_PRINT( "getRssi failed\r\n" );
komoritan 0:edaa24c1f5cd 509 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 510 return -1;
komoritan 0:edaa24c1f5cd 511 }
komoritan 0:edaa24c1f5cd 512
komoritan 0:edaa24c1f5cd 513 *rssi_p = (signed char)payload_buf_p->buf[2];
komoritan 0:edaa24c1f5cd 514
komoritan 0:edaa24c1f5cd 515 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 516 return 0;
komoritan 0:edaa24c1f5cd 517 }
komoritan 0:edaa24c1f5cd 518
komoritan 0:edaa24c1f5cd 519 int C_SNIC_WifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p)
komoritan 0:edaa24c1f5cd 520 {
komoritan 0:edaa24c1f5cd 521 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 522 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 523
komoritan 0:edaa24c1f5cd 524 if( status_p == NULL )
komoritan 0:edaa24c1f5cd 525 {
komoritan 0:edaa24c1f5cd 526 DEBUG_PRINT("getWifiStatus parameter error\r\n");
komoritan 0:edaa24c1f5cd 527 return -1;
komoritan 0:edaa24c1f5cd 528 }
komoritan 0:edaa24c1f5cd 529
komoritan 0:edaa24c1f5cd 530 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 531 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 532 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 533 {
komoritan 0:edaa24c1f5cd 534 DEBUG_PRINT("getWifiStatus payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 535 return -1;
komoritan 0:edaa24c1f5cd 536 }
komoritan 0:edaa24c1f5cd 537
komoritan 0:edaa24c1f5cd 538 C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T req;
komoritan 0:edaa24c1f5cd 539 // Make request
komoritan 0:edaa24c1f5cd 540 req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ;
komoritan 0:edaa24c1f5cd 541 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 542 req.interface = 0;
komoritan 0:edaa24c1f5cd 543
komoritan 0:edaa24c1f5cd 544 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 545 unsigned int command_len;
komoritan 0:edaa24c1f5cd 546 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 547 , sizeof(C_SNIC_Core::tagWIFI_GET_STATUS_REQ_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 548
komoritan 0:edaa24c1f5cd 549 // Send uart command request
komoritan 0:edaa24c1f5cd 550 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 551
komoritan 0:edaa24c1f5cd 552 int ret;
komoritan 0:edaa24c1f5cd 553 // Wait UART response
komoritan 0:edaa24c1f5cd 554 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 555 if( ret != 0 )
komoritan 0:edaa24c1f5cd 556 {
komoritan 0:edaa24c1f5cd 557 DEBUG_PRINT( "getWifiStatus failed\r\n" );
komoritan 0:edaa24c1f5cd 558 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 559 return -1;
komoritan 0:edaa24c1f5cd 560 }
komoritan 0:edaa24c1f5cd 561
komoritan 0:edaa24c1f5cd 562 // set status
komoritan 0:edaa24c1f5cd 563 status_p->status = (E_WIFI_STATUS)payload_buf_p->buf[2];
komoritan 0:edaa24c1f5cd 564
komoritan 0:edaa24c1f5cd 565 // set Mac address
komoritan 0:edaa24c1f5cd 566 if( status_p->status != e_STATUS_OFF )
komoritan 0:edaa24c1f5cd 567 {
komoritan 0:edaa24c1f5cd 568 memcpy( status_p->mac_address, &payload_buf_p->buf[3], BSSID_MAC_LENTH );
komoritan 0:edaa24c1f5cd 569 }
komoritan 0:edaa24c1f5cd 570
komoritan 0:edaa24c1f5cd 571 // set SSID
komoritan 0:edaa24c1f5cd 572 if( ( status_p->status == e_STA_JOINED ) || ( status_p->status == e_AP_STARTED ) )
komoritan 0:edaa24c1f5cd 573 {
komoritan 0:edaa24c1f5cd 574 memcpy( status_p->ssid, &payload_buf_p->buf[9], strlen( (char *)&payload_buf_p->buf[9]) );
komoritan 0:edaa24c1f5cd 575 }
komoritan 0:edaa24c1f5cd 576
komoritan 0:edaa24c1f5cd 577 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 578 return 0;
komoritan 0:edaa24c1f5cd 579 }
komoritan 0:edaa24c1f5cd 580
komoritan 0:edaa24c1f5cd 581 int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP
komoritan 0:edaa24c1f5cd 582 , const char *ip_p, const char *mask_p, const char *gateway_p )
komoritan 0:edaa24c1f5cd 583 {
komoritan 0:edaa24c1f5cd 584 // Parameter check
komoritan 0:edaa24c1f5cd 585 if( is_DHCP == false )
komoritan 0:edaa24c1f5cd 586 {
komoritan 0:edaa24c1f5cd 587 if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) )
komoritan 0:edaa24c1f5cd 588 {
komoritan 0:edaa24c1f5cd 589 DEBUG_PRINT("setIPConfig parameter error\r\n");
komoritan 0:edaa24c1f5cd 590 return -1;
komoritan 0:edaa24c1f5cd 591 }
komoritan 0:edaa24c1f5cd 592 }
komoritan 0:edaa24c1f5cd 593
komoritan 0:edaa24c1f5cd 594 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
komoritan 0:edaa24c1f5cd 595 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
komoritan 0:edaa24c1f5cd 596
komoritan 0:edaa24c1f5cd 597 // Get buffer for response payload from MemoryPool
komoritan 0:edaa24c1f5cd 598 tagMEMPOOL_BLOCK_T *payload_buf_p = snic_core_p->allocCmdBuf();
komoritan 0:edaa24c1f5cd 599 if( payload_buf_p == NULL )
komoritan 0:edaa24c1f5cd 600 {
komoritan 0:edaa24c1f5cd 601 DEBUG_PRINT("setIPConfig payload_buf_p NULL\r\n");
komoritan 0:edaa24c1f5cd 602 return -1;
komoritan 0:edaa24c1f5cd 603 }
komoritan 0:edaa24c1f5cd 604
komoritan 0:edaa24c1f5cd 605 unsigned char *command_array_p = snic_core_p->getCommandBuf();
komoritan 0:edaa24c1f5cd 606 unsigned int command_len;
komoritan 0:edaa24c1f5cd 607 if( is_DHCP == true )
komoritan 0:edaa24c1f5cd 608 {
komoritan 0:edaa24c1f5cd 609 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req;
komoritan 0:edaa24c1f5cd 610 // Make request
komoritan 0:edaa24c1f5cd 611 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
komoritan 0:edaa24c1f5cd 612 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 613 req.interface = 0;
komoritan 0:edaa24c1f5cd 614 req.dhcp = 1;
komoritan 0:edaa24c1f5cd 615
komoritan 0:edaa24c1f5cd 616 // Preparation of command
komoritan 0:edaa24c1f5cd 617 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 618 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 619 }
komoritan 0:edaa24c1f5cd 620 else
komoritan 0:edaa24c1f5cd 621 {
komoritan 0:edaa24c1f5cd 622 C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req;
komoritan 0:edaa24c1f5cd 623 // Make request
komoritan 0:edaa24c1f5cd 624 req.cmd_sid = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
komoritan 0:edaa24c1f5cd 625 req.seq = mUartRequestSeq++;
komoritan 0:edaa24c1f5cd 626 req.interface = 0;
komoritan 0:edaa24c1f5cd 627 req.dhcp = 0;
komoritan 0:edaa24c1f5cd 628
komoritan 0:edaa24c1f5cd 629 // Set paramter of address
komoritan 0:edaa24c1f5cd 630 int addr_temp;
komoritan 0:edaa24c1f5cd 631 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p );
komoritan 0:edaa24c1f5cd 632 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr );
komoritan 0:edaa24c1f5cd 633 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p );
komoritan 0:edaa24c1f5cd 634 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask );
komoritan 0:edaa24c1f5cd 635 addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p );
komoritan 0:edaa24c1f5cd 636 C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway );
komoritan 0:edaa24c1f5cd 637
komoritan 0:edaa24c1f5cd 638 // Preparation of command
komoritan 0:edaa24c1f5cd 639 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
komoritan 0:edaa24c1f5cd 640 , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf_p->buf, command_array_p );
komoritan 0:edaa24c1f5cd 641 }
komoritan 0:edaa24c1f5cd 642 // Send uart command request
komoritan 0:edaa24c1f5cd 643 snic_core_p->sendUart( command_len, command_array_p );
komoritan 0:edaa24c1f5cd 644
komoritan 0:edaa24c1f5cd 645 int ret;
komoritan 0:edaa24c1f5cd 646 // Wait UART response
komoritan 0:edaa24c1f5cd 647 ret = uartCmdMgr_p->wait();
komoritan 0:edaa24c1f5cd 648 if( ret != 0 )
komoritan 0:edaa24c1f5cd 649 {
komoritan 0:edaa24c1f5cd 650 DEBUG_PRINT( "setIPConfig failed\r\n" );
komoritan 0:edaa24c1f5cd 651 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 652 return -1;
komoritan 0:edaa24c1f5cd 653 }
komoritan 0:edaa24c1f5cd 654
komoritan 0:edaa24c1f5cd 655 if( uartCmdMgr_p->getCommandStatus() != 0 )
komoritan 0:edaa24c1f5cd 656 {
komoritan 0:edaa24c1f5cd 657 DEBUG_PRINT("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
komoritan 0:edaa24c1f5cd 658 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 659 return -1;
komoritan 0:edaa24c1f5cd 660 }
komoritan 0:edaa24c1f5cd 661
komoritan 0:edaa24c1f5cd 662 snic_core_p->freeCmdBuf( payload_buf_p );
komoritan 0:edaa24c1f5cd 663 return ret;
komoritan 0:edaa24c1f5cd 664 }