for EthernetInterface library compatibility.\\ ** Unoffical fix. may be a problem. **

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

Fork of SNICInterface by muRata

Revision:
31:15c22824cc46
Parent:
29:6a0ba999597d
Child:
36:f33fcf5975ab
diff -r 944b8c04b5ff -r 15c22824cc46 SNIC_WifiInterface.cpp
--- a/SNIC_WifiInterface.cpp	Tue May 27 01:33:04 2014 +0000
+++ b/SNIC_WifiInterface.cpp	Thu May 29 03:23:21 2014 +0000
@@ -559,3 +559,87 @@
     snic_core_p->freeCmdBuf( payload_buf );
     return 0;
 }
+
+int C_SNIC_WifiInterface::setIPConfig( bool is_DHCP
+    , const char *ip_p, const char *mask_p, const char *gateway_p )
+{
+    // Parameter check
+    if( is_DHCP == false )
+    {
+        if( (ip_p == NULL) || (mask_p == NULL) ||(gateway_p == NULL) )
+        {
+            printf("setIPConfig parameter error\r\n");
+            return -1;
+        }            
+    }
+
+    C_SNIC_Core               *snic_core_p  = C_SNIC_Core::getInstance();
+    C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
+
+    // Get buffer for response payload from MemoryPool
+    tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
+    if( payload_buf == NULL )
+    {
+        printf("setIPConfig payload_buf NULL\r\n");
+        return -1;
+    }
+
+    unsigned char *command_array = snic_core_p->getCommandBuf();
+    unsigned int  command_len;
+    if( is_DHCP == true )
+    {
+        C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T req;
+        // Make request
+        req.cmd_sid   = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
+        req.seq       = mUartRequestSeq++;
+        req.interface = 0;
+        req.dhcp      = 1;
+        
+        // Preparation of command
+        command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_DHCP_T), payload_buf->buf, command_array );
+    }
+    else
+    {
+        C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T req;
+        // Make request
+        req.cmd_sid   = UART_CMD_SID_SNIC_IP_CONFIG_REQ;
+        req.seq       = mUartRequestSeq++;
+        req.interface = 0;
+        req.dhcp      = 0;
+
+        // Set paramter of address
+        int addr_temp;
+        addr_temp = C_SNIC_UartMsgUtil::addrToInteger( ip_p );
+        C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.ip_addr );
+        addr_temp = C_SNIC_UartMsgUtil::addrToInteger( mask_p );
+        C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.netmask );
+        addr_temp = C_SNIC_UartMsgUtil::addrToInteger( gateway_p );
+        C_SNIC_UartMsgUtil::convertIntToByteAdday( addr_temp, (char *)req.gateway );
+
+        // Preparation of command
+        command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
+                            , sizeof(C_SNIC_Core::tagSNIC_IP_CONFIG_REQ_STATIC_T), payload_buf->buf, command_array );
+    }
+    // Send uart command request
+    snic_core_p->sendUart( command_len, command_array );
+    
+    int ret;
+    // Wait UART response
+    ret = uartCmdMgr_p->wait();
+    if( ret != 0 )
+    {
+        printf( "setIPConfig failed\r\n" );
+        snic_core_p->freeCmdBuf( payload_buf );
+        return -1;
+    }
+    
+    if( uartCmdMgr_p->getCommandStatus() != 0 )
+    {
+        printf("setIPConfig status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
+        ret = -1;
+    }
+
+    snic_core_p->freeCmdBuf( payload_buf );
+    return 0;
+}