ban4jp - / SNICInterface_PullReq

Dependents:   SNIC-httpclient-example SNIC-ntpclient-example

Fork of SNICInterface by muRata

Committer:
kishino
Date:
Tue Mar 18 02:57:24 2014 +0000
Revision:
10:49ffd373066b
Parent:
9:a98b45e766c8
[Refactoring]Created the common function for the preparation of request command of UART.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 8:50d2509479cd 1 #include "SNICwifiInterface.h"
kishino 8:50d2509479cd 2 #include "SNICwifi_uartmsg.h"
kishino 8:50d2509479cd 3
kishino 8:50d2509479cd 4 using namespace murata_wifi;
kishino 8:50d2509479cd 5
kishino 8:50d2509479cd 6 C_SNICwifiInterface::C_SNICwifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud):
kishino 8:50d2509479cd 7 C_SNICwifi(tx, rx, cts, rts, reset, alarm, baud)
kishino 8:50d2509479cd 8 {
kishino 8:50d2509479cd 9 }
kishino 8:50d2509479cd 10
kishino 8:50d2509479cd 11 int C_SNICwifiInterface::init()
kishino 8:50d2509479cd 12 {
kishino 8:50d2509479cd 13 /* Initialize UART */
kishino 8:50d2509479cd 14 initUart();
kishino 8:50d2509479cd 15
kishino 8:50d2509479cd 16 /* Initialize SNIC API */
kishino 9:a98b45e766c8 17 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 18 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 19 if( payload_buf == NULL )
kishino 8:50d2509479cd 20 {
kishino 8:50d2509479cd 21 printf("snic_init payload_buf NULL\r\n");
kishino 8:50d2509479cd 22 return -1;
kishino 8:50d2509479cd 23 }
kishino 8:50d2509479cd 24
kishino 8:50d2509479cd 25 tagSNIC_INIT_REQ_T req;
kishino 8:50d2509479cd 26 // Make request
kishino 8:50d2509479cd 27 req.cmd_sid = UART_CMD_SID_SNIC_INIT_REQ;
kishino 8:50d2509479cd 28 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 29 req.buf_size = 0x800;
kishino 8:50d2509479cd 30
kishino 8:50d2509479cd 31 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 32 unsigned int command_len;
kishino 10:49ffd373066b 33 // Preparation of command
kishino 10:49ffd373066b 34 command_len = preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 35 , sizeof(tagSNIC_INIT_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 36
kishino 8:50d2509479cd 37 // Send uart command request
kishino 8:50d2509479cd 38 sendUart( command_len, command_array );
kishino 10:49ffd373066b 39
kishino 10:49ffd373066b 40 int ret;
kishino 8:50d2509479cd 41 // Wait UART response
kishino 8:50d2509479cd 42 ret = mUartCommand.wait();
kishino 8:50d2509479cd 43 if( ret != 0 )
kishino 8:50d2509479cd 44 {
kishino 8:50d2509479cd 45 printf( "snic_init failed\r\n" );
kishino 9:a98b45e766c8 46 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 47 return -1;
kishino 8:50d2509479cd 48 }
kishino 8:50d2509479cd 49
kishino 8:50d2509479cd 50 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 51 {
kishino 8:50d2509479cd 52 printf("snic_init status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 53 ret = -1;
kishino 8:50d2509479cd 54 }
kishino 9:a98b45e766c8 55 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 56
kishino 8:50d2509479cd 57 return ret;
kishino 8:50d2509479cd 58 }
kishino 8:50d2509479cd 59
kishino 8:50d2509479cd 60 int C_SNICwifiInterface::getFWVersion( unsigned char *version_p )
kishino 8:50d2509479cd 61 {
kishino 8:50d2509479cd 62 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 63 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 64 if( payload_buf == NULL )
kishino 8:50d2509479cd 65 {
kishino 8:50d2509479cd 66 printf("getFWVersion payload_buf NULL\r\n");
kishino 8:50d2509479cd 67 return -1;
kishino 8:50d2509479cd 68 }
kishino 8:50d2509479cd 69
kishino 8:50d2509479cd 70 tagGEN_FW_VER_GET_REQ_T req;
kishino 8:50d2509479cd 71 // Make request
kishino 8:50d2509479cd 72 req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ;
kishino 8:50d2509479cd 73 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 74
kishino 10:49ffd373066b 75 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 76 unsigned int command_len;
kishino 10:49ffd373066b 77 // Preparation of command
kishino 10:49ffd373066b 78 command_len = preparationSendCommand( UART_CMD_ID_GEN, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 79 , sizeof(tagGEN_FW_VER_GET_REQ_T), payload_buf->buf, command_array );
kishino 10:49ffd373066b 80
kishino 8:50d2509479cd 81 int ret;
kishino 8:50d2509479cd 82
kishino 8:50d2509479cd 83 // Send uart command request
kishino 8:50d2509479cd 84 sendUart( command_len, command_array );
kishino 8:50d2509479cd 85
kishino 8:50d2509479cd 86 // Wait UART response
kishino 8:50d2509479cd 87 ret = mUartCommand.wait();
kishino 8:50d2509479cd 88 if( ret != 0 )
kishino 8:50d2509479cd 89 {
kishino 8:50d2509479cd 90 printf( "getFWversion failed\r\n" );
kishino 9:a98b45e766c8 91 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 92 return -1;
kishino 8:50d2509479cd 93 }
kishino 8:50d2509479cd 94
kishino 8:50d2509479cd 95 if( mUartCommand.getCommandStatus() == 0 )
kishino 8:50d2509479cd 96 {
kishino 8:50d2509479cd 97 unsigned char version_len = payload_buf->buf[3];
kishino 8:50d2509479cd 98 memcpy( version_p, &payload_buf->buf[4], version_len );
kishino 8:50d2509479cd 99 }
kishino 9:a98b45e766c8 100 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 101 return 0;
kishino 8:50d2509479cd 102 }
kishino 8:50d2509479cd 103
kishino 8:50d2509479cd 104 int C_SNICwifiInterface::connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type
kishino 8:50d2509479cd 105 , const char *sec_key_p, unsigned char sec_key_len)
kishino 8:50d2509479cd 106 {
kishino 8:50d2509479cd 107 // Parameter check(SSID)
kishino 8:50d2509479cd 108 if( (ssid_p == NULL) || (ssid_len == 0) )
kishino 8:50d2509479cd 109 {
kishino 8:50d2509479cd 110 printf( "connect failed [ parameter NG:SSID ]\r\n" );
kishino 8:50d2509479cd 111 return -1;
kishino 8:50d2509479cd 112 }
kishino 8:50d2509479cd 113
kishino 8:50d2509479cd 114 // Parameter check(Security key)
kishino 8:50d2509479cd 115 if( (sec_type != e_SEC_OPEN) && ( (sec_key_len == 0) || (sec_key_p == NULL) ) )
kishino 8:50d2509479cd 116 {
kishino 8:50d2509479cd 117 printf( "connect failed [ parameter NG:Security key ]\r\n" );
kishino 8:50d2509479cd 118 return -1;
kishino 8:50d2509479cd 119 }
kishino 8:50d2509479cd 120
kishino 9:a98b45e766c8 121 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 122 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 123 if( payload_buf == NULL )
kishino 8:50d2509479cd 124 {
kishino 8:50d2509479cd 125 printf("connect payload_buf NULL\r\n");
kishino 8:50d2509479cd 126 return -1;
kishino 8:50d2509479cd 127 }
kishino 8:50d2509479cd 128
kishino 10:49ffd373066b 129 unsigned char buf[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 130 unsigned int buf_len = 0;
kishino 10:49ffd373066b 131 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 132 unsigned int command_len;
kishino 8:50d2509479cd 133
kishino 8:50d2509479cd 134 memset( buf, 0, UART_REQUEST_PAYLOAD_MAX );
kishino 8:50d2509479cd 135 // Make request
kishino 8:50d2509479cd 136 buf[0] = UART_CMD_SID_WIFI_JOIN_REQ;
kishino 8:50d2509479cd 137 buf_len++;
kishino 8:50d2509479cd 138 buf[1] = mUartRequestSeq++;
kishino 8:50d2509479cd 139 buf_len++;
kishino 8:50d2509479cd 140 // SSID
kishino 8:50d2509479cd 141 memcpy( &buf[2], ssid_p, ssid_len );
kishino 8:50d2509479cd 142 buf_len += ssid_len;
kishino 8:50d2509479cd 143 buf_len++;
kishino 8:50d2509479cd 144
kishino 8:50d2509479cd 145 // Security mode
kishino 8:50d2509479cd 146 buf[ buf_len ] = (unsigned char)sec_type;
kishino 8:50d2509479cd 147 buf_len++;
kishino 8:50d2509479cd 148
kishino 8:50d2509479cd 149 // Security key
kishino 8:50d2509479cd 150 if( sec_type != e_SEC_OPEN )
kishino 8:50d2509479cd 151 {
kishino 8:50d2509479cd 152 buf[ buf_len ] = sec_key_len;
kishino 8:50d2509479cd 153 buf_len++;
kishino 8:50d2509479cd 154 if( sec_key_len > 0 )
kishino 8:50d2509479cd 155 {
kishino 8:50d2509479cd 156 memcpy( &buf[buf_len], sec_key_p, sec_key_len );
kishino 8:50d2509479cd 157 buf_len += sec_key_len;
kishino 8:50d2509479cd 158 }
kishino 8:50d2509479cd 159 }
kishino 10:49ffd373066b 160
kishino 10:49ffd373066b 161 // Preparation of command
kishino 10:49ffd373066b 162 command_len = preparationSendCommand( UART_CMD_ID_WIFI, UART_CMD_SID_WIFI_JOIN_REQ, buf
kishino 10:49ffd373066b 163 , buf_len, payload_buf->buf, command_array );
kishino 10:49ffd373066b 164
kishino 8:50d2509479cd 165 // Send uart command request
kishino 8:50d2509479cd 166 sendUart( command_len, command_array );
kishino 8:50d2509479cd 167
kishino 10:49ffd373066b 168 int ret;
kishino 8:50d2509479cd 169 // Wait UART response
kishino 8:50d2509479cd 170 ret = mUartCommand.wait();
kishino 8:50d2509479cd 171 if( ret != 0 )
kishino 8:50d2509479cd 172 {
kishino 8:50d2509479cd 173 printf( "join failed\r\n" );
kishino 9:a98b45e766c8 174 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 175 return -1;
kishino 8:50d2509479cd 176 }
kishino 8:50d2509479cd 177
kishino 8:50d2509479cd 178 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 179 {
kishino 8:50d2509479cd 180 printf("join status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 181 ret = -1;
kishino 8:50d2509479cd 182 }
kishino 9:a98b45e766c8 183 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 184
kishino 8:50d2509479cd 185 return ret;
kishino 8:50d2509479cd 186 }
kishino 8:50d2509479cd 187
kishino 8:50d2509479cd 188 int C_SNICwifiInterface::disconnect()
kishino 8:50d2509479cd 189 {
kishino 9:a98b45e766c8 190 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 191 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 192 if( payload_buf == NULL )
kishino 8:50d2509479cd 193 {
kishino 8:50d2509479cd 194 printf("disconnect payload_buf NULL\r\n");
kishino 8:50d2509479cd 195 return -1;
kishino 8:50d2509479cd 196 }
kishino 8:50d2509479cd 197
kishino 8:50d2509479cd 198 tagWIFI_DISCONNECT_REQ_T req;
kishino 8:50d2509479cd 199 // Make request
kishino 8:50d2509479cd 200 req.cmd_sid = UART_CMD_SID_WIFI_DISCONNECT_REQ;
kishino 8:50d2509479cd 201 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 202
kishino 10:49ffd373066b 203 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 204 unsigned int command_len;
kishino 10:49ffd373066b 205 // Preparation of command
kishino 10:49ffd373066b 206 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 207 , sizeof(tagWIFI_DISCONNECT_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 208
kishino 8:50d2509479cd 209 // Send uart command request
kishino 8:50d2509479cd 210 sendUart( command_len, command_array );
kishino 8:50d2509479cd 211
kishino 10:49ffd373066b 212 int ret;
kishino 8:50d2509479cd 213 // Wait UART response
kishino 8:50d2509479cd 214 ret = mUartCommand.wait();
kishino 8:50d2509479cd 215 if( ret != 0 )
kishino 8:50d2509479cd 216 {
kishino 8:50d2509479cd 217 printf( "disconnect failed\r\n" );
kishino 9:a98b45e766c8 218 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 219 return -1;
kishino 8:50d2509479cd 220 }
kishino 8:50d2509479cd 221
kishino 8:50d2509479cd 222 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 223 {
kishino 8:50d2509479cd 224 printf("disconnect status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 225 ret = -1;
kishino 8:50d2509479cd 226 }
kishino 9:a98b45e766c8 227 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 228 return ret;
kishino 8:50d2509479cd 229 }
kishino 8:50d2509479cd 230
kishino 8:50d2509479cd 231 int C_SNICwifiInterface::scan( const char *ssid_p, unsigned char *bssid_p
kishino 8:50d2509479cd 232 , void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) )
kishino 8:50d2509479cd 233 {
kishino 9:a98b45e766c8 234 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 235 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 236 if( payload_buf == NULL )
kishino 8:50d2509479cd 237 {
kishino 8:50d2509479cd 238 printf("scan payload_buf NULL\r\n");
kishino 8:50d2509479cd 239 return -1;
kishino 8:50d2509479cd 240 }
kishino 8:50d2509479cd 241
kishino 8:50d2509479cd 242 tagWIFI_SCAN_REQ_T req;
kishino 10:49ffd373066b 243 unsigned int buf_len = 0;
kishino 8:50d2509479cd 244
kishino 8:50d2509479cd 245 memset( &req, 0, sizeof(tagWIFI_SCAN_REQ_T) );
kishino 8:50d2509479cd 246 // Make request
kishino 8:50d2509479cd 247 req.cmd_sid = UART_CMD_SID_WIFI_SCAN_REQ;
kishino 8:50d2509479cd 248 buf_len++;
kishino 8:50d2509479cd 249 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 250 buf_len++;
kishino 8:50d2509479cd 251
kishino 8:50d2509479cd 252 // Set scan type(Active scan)
kishino 8:50d2509479cd 253 req.scan_type = 0;
kishino 8:50d2509479cd 254 buf_len++;
kishino 8:50d2509479cd 255 // Set bss type(any)
kishino 8:50d2509479cd 256 req.bss_type = 2;
kishino 8:50d2509479cd 257 buf_len++;
kishino 8:50d2509479cd 258 // Set BSSID
kishino 8:50d2509479cd 259 if( bssid_p != NULL )
kishino 8:50d2509479cd 260 {
kishino 8:50d2509479cd 261 memcpy( req.bssid, bssid_p, BSSID_MAC_LENTH );
kishino 8:50d2509479cd 262 }
kishino 8:50d2509479cd 263 buf_len += BSSID_MAC_LENTH;
kishino 8:50d2509479cd 264 // Set channel list(0)
kishino 8:50d2509479cd 265 req.chan_list = 0;
kishino 8:50d2509479cd 266 buf_len++;
kishino 8:50d2509479cd 267 //Set SSID
kishino 8:50d2509479cd 268 if( ssid_p != NULL )
kishino 8:50d2509479cd 269 {
kishino 8:50d2509479cd 270 strcpy( (char *)req.ssid, ssid_p );
kishino 8:50d2509479cd 271 buf_len += strlen(ssid_p);
kishino 8:50d2509479cd 272 }
kishino 8:50d2509479cd 273 buf_len++;
kishino 8:50d2509479cd 274
kishino 10:49ffd373066b 275 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 276 unsigned int command_len;
kishino 10:49ffd373066b 277 // Preparation of command
kishino 10:49ffd373066b 278 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 279 , buf_len, payload_buf->buf, command_array );
kishino 8:50d2509479cd 280
kishino 8:50d2509479cd 281 // Set scan result callback
kishino 8:50d2509479cd 282 mUartCommand.setScanResultHandler( result_handler_p );
kishino 8:50d2509479cd 283
kishino 8:50d2509479cd 284 // Send uart command request
kishino 8:50d2509479cd 285 sendUart( command_len, command_array );
kishino 8:50d2509479cd 286
kishino 10:49ffd373066b 287 int ret;
kishino 8:50d2509479cd 288 // Wait UART response
kishino 8:50d2509479cd 289 ret = mUartCommand.wait();
kishino 8:50d2509479cd 290 printf( "scan wait:%d\r\n", ret );
kishino 8:50d2509479cd 291 if( ret != 0 )
kishino 8:50d2509479cd 292 {
kishino 8:50d2509479cd 293 printf( "scan failed\r\n" );
kishino 9:a98b45e766c8 294 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 295 return -1;
kishino 8:50d2509479cd 296 }
kishino 8:50d2509479cd 297
kishino 8:50d2509479cd 298 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 299 {
kishino 8:50d2509479cd 300 printf("scan status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 301 ret = -1;
kishino 8:50d2509479cd 302 }
kishino 8:50d2509479cd 303
kishino 9:a98b45e766c8 304 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 305
kishino 8:50d2509479cd 306 return ret;
kishino 8:50d2509479cd 307 }
kishino 8:50d2509479cd 308
kishino 8:50d2509479cd 309 int C_SNICwifiInterface::wifi_on( const char *country_p )
kishino 8:50d2509479cd 310 {
kishino 8:50d2509479cd 311 // Parameter check
kishino 8:50d2509479cd 312 if( country_p == NULL )
kishino 8:50d2509479cd 313 {
kishino 8:50d2509479cd 314 printf("wifi_on parameter error\r\n");
kishino 8:50d2509479cd 315 return -1;
kishino 8:50d2509479cd 316 }
kishino 8:50d2509479cd 317
kishino 9:a98b45e766c8 318 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 319 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 320 if( payload_buf == NULL )
kishino 8:50d2509479cd 321 {
kishino 8:50d2509479cd 322 printf("wifi_on payload_buf NULL\r\n");
kishino 8:50d2509479cd 323 return -1;
kishino 8:50d2509479cd 324 }
kishino 8:50d2509479cd 325
kishino 8:50d2509479cd 326 tagWIFI_ON_REQ_T req;
kishino 8:50d2509479cd 327 // Make request
kishino 8:50d2509479cd 328 req.cmd_sid = UART_CMD_SID_WIFI_ON_REQ;
kishino 8:50d2509479cd 329 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 330 memcpy( req.country, country_p, COUNTRYC_CODE_LENTH );
kishino 8:50d2509479cd 331
kishino 10:49ffd373066b 332 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 333 unsigned int command_len;
kishino 10:49ffd373066b 334 // Preparation of command
kishino 10:49ffd373066b 335 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 336 , sizeof(tagWIFI_ON_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 337
kishino 8:50d2509479cd 338 // Send uart command request
kishino 8:50d2509479cd 339 sendUart( command_len, command_array );
kishino 8:50d2509479cd 340
kishino 10:49ffd373066b 341 int ret;
kishino 8:50d2509479cd 342 // Wait UART response
kishino 8:50d2509479cd 343 ret = mUartCommand.wait();
kishino 8:50d2509479cd 344 if( ret != 0 )
kishino 8:50d2509479cd 345 {
kishino 8:50d2509479cd 346 printf( "wifi_on failed\r\n" );
kishino 9:a98b45e766c8 347 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 348 return -1;
kishino 8:50d2509479cd 349 }
kishino 8:50d2509479cd 350
kishino 8:50d2509479cd 351 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 352 {
kishino 8:50d2509479cd 353 printf("wifi_on status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 354 ret = -1;
kishino 8:50d2509479cd 355 }
kishino 9:a98b45e766c8 356 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 357
kishino 8:50d2509479cd 358 return ret;
kishino 8:50d2509479cd 359 }
kishino 8:50d2509479cd 360
kishino 8:50d2509479cd 361 int C_SNICwifiInterface::wifi_off()
kishino 8:50d2509479cd 362 {
kishino 9:a98b45e766c8 363 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 364 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 365 if( payload_buf == NULL )
kishino 8:50d2509479cd 366 {
kishino 8:50d2509479cd 367 printf("wifi_off payload_buf NULL\r\n");
kishino 8:50d2509479cd 368 return -1;
kishino 8:50d2509479cd 369 }
kishino 8:50d2509479cd 370
kishino 8:50d2509479cd 371 tagWIFI_OFF_REQ_T req;
kishino 8:50d2509479cd 372 // Make request
kishino 8:50d2509479cd 373 req.cmd_sid = UART_CMD_SID_WIFI_OFF_REQ;
kishino 8:50d2509479cd 374 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 375
kishino 10:49ffd373066b 376 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 377 unsigned int command_len;
kishino 10:49ffd373066b 378 // Preparation of command
kishino 10:49ffd373066b 379 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 380 , sizeof(tagWIFI_OFF_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 381
kishino 8:50d2509479cd 382 // Send uart command request
kishino 8:50d2509479cd 383 sendUart( command_len, command_array );
kishino 8:50d2509479cd 384
kishino 10:49ffd373066b 385 int ret;
kishino 8:50d2509479cd 386 // Wait UART response
kishino 8:50d2509479cd 387 ret = mUartCommand.wait();
kishino 8:50d2509479cd 388 if( ret != 0 )
kishino 8:50d2509479cd 389 {
kishino 8:50d2509479cd 390 printf( "wifi_off failed\r\n" );
kishino 9:a98b45e766c8 391 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 392 return -1;
kishino 8:50d2509479cd 393 }
kishino 8:50d2509479cd 394
kishino 8:50d2509479cd 395 if( mUartCommand.getCommandStatus() != 0 )
kishino 8:50d2509479cd 396 {
kishino 8:50d2509479cd 397 printf("wifi_off status:%02x\r\n", mUartCommand.getCommandStatus());
kishino 8:50d2509479cd 398 ret = -1;
kishino 8:50d2509479cd 399 }
kishino 9:a98b45e766c8 400 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 401
kishino 8:50d2509479cd 402 return ret;
kishino 8:50d2509479cd 403 }
kishino 8:50d2509479cd 404
kishino 8:50d2509479cd 405 int C_SNICwifiInterface::getRssi( signed char *rssi_p )
kishino 8:50d2509479cd 406 {
kishino 8:50d2509479cd 407 if( rssi_p == NULL )
kishino 8:50d2509479cd 408 {
kishino 8:50d2509479cd 409 printf("getRssi parameter error\r\n");
kishino 8:50d2509479cd 410 return -1;
kishino 8:50d2509479cd 411 }
kishino 8:50d2509479cd 412
kishino 8:50d2509479cd 413 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 414 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 415 if( payload_buf == NULL )
kishino 8:50d2509479cd 416 {
kishino 8:50d2509479cd 417 printf("getRssi payload_buf NULL\r\n");
kishino 8:50d2509479cd 418 return -1;
kishino 8:50d2509479cd 419 }
kishino 8:50d2509479cd 420
kishino 8:50d2509479cd 421 tagWIFI_GET_STA_RSSI_REQ_T req;
kishino 8:50d2509479cd 422
kishino 8:50d2509479cd 423 // Make request
kishino 8:50d2509479cd 424 req.cmd_sid = UART_CMD_SID_WIFI_GET_STA_RSSI_REQ;
kishino 8:50d2509479cd 425 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 426
kishino 10:49ffd373066b 427 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 428 unsigned int command_len;
kishino 10:49ffd373066b 429 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 430 , sizeof(tagWIFI_GET_STA_RSSI_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 431
kishino 10:49ffd373066b 432 int ret;
kishino 8:50d2509479cd 433 // Send uart command request
kishino 8:50d2509479cd 434 sendUart( command_len, command_array );
kishino 8:50d2509479cd 435
kishino 8:50d2509479cd 436 // Wait UART response
kishino 8:50d2509479cd 437 ret = mUartCommand.wait();
kishino 8:50d2509479cd 438 if( ret != 0 )
kishino 8:50d2509479cd 439 {
kishino 8:50d2509479cd 440 printf( "getRssi failed\r\n" );
kishino 9:a98b45e766c8 441 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 442 return -1;
kishino 8:50d2509479cd 443 }
kishino 8:50d2509479cd 444
kishino 8:50d2509479cd 445 *rssi_p = (signed char)payload_buf->buf[2];
kishino 8:50d2509479cd 446
kishino 9:a98b45e766c8 447 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 448 return 0;
kishino 8:50d2509479cd 449 }
kishino 8:50d2509479cd 450
kishino 8:50d2509479cd 451 int C_SNICwifiInterface::getWifiStatus( tagWIFI_STATUS_T *status_p)
kishino 8:50d2509479cd 452 {
kishino 8:50d2509479cd 453 if( status_p == NULL )
kishino 8:50d2509479cd 454 {
kishino 8:50d2509479cd 455 printf("getWifiStatus parameter error\r\n");
kishino 8:50d2509479cd 456 return -1;
kishino 8:50d2509479cd 457 }
kishino 8:50d2509479cd 458
kishino 8:50d2509479cd 459 // Get buffer for response payload from MemoryPool
kishino 9:a98b45e766c8 460 tagMEMPOOL_BLOCK_T *payload_buf = getAlocCmdBuf();
kishino 8:50d2509479cd 461 if( payload_buf == NULL )
kishino 8:50d2509479cd 462 {
kishino 8:50d2509479cd 463 printf("getWifiStatus payload_buf NULL\r\n");
kishino 8:50d2509479cd 464 return -1;
kishino 8:50d2509479cd 465 }
kishino 8:50d2509479cd 466
kishino 8:50d2509479cd 467 tagWIFI_GET_STATUS_REQ_T req;
kishino 8:50d2509479cd 468 // Make request
kishino 8:50d2509479cd 469 req.cmd_sid = UART_CMD_SID_WIFI_GET_STATUS_REQ;
kishino 8:50d2509479cd 470 req.seq = mUartRequestSeq++;
kishino 8:50d2509479cd 471 req.interface = 0;
kishino 8:50d2509479cd 472
kishino 10:49ffd373066b 473 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 10:49ffd373066b 474 unsigned int command_len;
kishino 10:49ffd373066b 475 command_len = preparationSendCommand( UART_CMD_ID_WIFI, req.cmd_sid, (unsigned char *)&req
kishino 10:49ffd373066b 476 , sizeof(tagWIFI_GET_STATUS_REQ_T), payload_buf->buf, command_array );
kishino 8:50d2509479cd 477
kishino 8:50d2509479cd 478 // Send uart command request
kishino 8:50d2509479cd 479 sendUart( command_len, command_array );
kishino 8:50d2509479cd 480
kishino 10:49ffd373066b 481 int ret;
kishino 8:50d2509479cd 482 // Wait UART response
kishino 8:50d2509479cd 483 ret = mUartCommand.wait();
kishino 8:50d2509479cd 484 if( ret != 0 )
kishino 8:50d2509479cd 485 {
kishino 8:50d2509479cd 486 printf( "getWifiStatus failed\r\n" );
kishino 9:a98b45e766c8 487 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 488 return -1;
kishino 8:50d2509479cd 489 }
kishino 8:50d2509479cd 490
kishino 8:50d2509479cd 491 // set status
kishino 8:50d2509479cd 492 status_p->status = (E_WIFI_STATUS)payload_buf->buf[2];
kishino 8:50d2509479cd 493
kishino 8:50d2509479cd 494 // set Mac address
kishino 8:50d2509479cd 495 if( status_p->status != e_STATUS_OFF )
kishino 8:50d2509479cd 496 {
kishino 8:50d2509479cd 497 memcpy( status_p->mac_address, &payload_buf->buf[3], BSSID_MAC_LENTH );
kishino 8:50d2509479cd 498 }
kishino 8:50d2509479cd 499
kishino 8:50d2509479cd 500 // set SSID
kishino 8:50d2509479cd 501 if( ( status_p->status == e_STA_JOINED ) == ( status_p->status == e_AP_STARTED ) )
kishino 8:50d2509479cd 502 {
kishino 8:50d2509479cd 503 memcpy( status_p->ssid, &payload_buf->buf[9], strlen( (char *)&payload_buf->buf[9]) );
kishino 8:50d2509479cd 504 }
kishino 8:50d2509479cd 505
kishino 9:a98b45e766c8 506 freeCmdBuf( payload_buf );
kishino 8:50d2509479cd 507 return 0;
kishino 8:50d2509479cd 508 }