debug version

Dependents:   HTTPClient_WiFi_HelloWorld_src

Fork of SNICInterface by muRata

Committer:
kishino
Date:
Tue Mar 25 02:21:11 2014 +0000
Revision:
13:53e6471d5753
Parent:
12:0254eaccfda2
Child:
14:54378c96d285
Created the function of the TCP / IP client. (packet send, receive)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 12:0254eaccfda2 1 #ifndef _SNIC_CORE_H_
kishino 12:0254eaccfda2 2 #define _SNIC_CORE_H_
kishino 12:0254eaccfda2 3
kishino 12:0254eaccfda2 4 #include "mbed.h"
kishino 12:0254eaccfda2 5 #include "rtos.h"
kishino 12:0254eaccfda2 6 #include "RawSerial.h"
kishino 12:0254eaccfda2 7 #include "CBuffer.h"
kishino 12:0254eaccfda2 8
kishino 12:0254eaccfda2 9 #include "SNIC_UartCommandManager.h"
kishino 12:0254eaccfda2 10
kishino 12:0254eaccfda2 11 namespace murata_wifi
kishino 12:0254eaccfda2 12 {
kishino 12:0254eaccfda2 13 #define UART_REQUEST_PAYLOAD_MAX 256
kishino 12:0254eaccfda2 14
kishino 12:0254eaccfda2 15 #define MEMPOOL_BLOCK_SIZE 2048
kishino 12:0254eaccfda2 16 #define MEMPOOL_PAYLOAD_NUM 1
kishino 12:0254eaccfda2 17 typedef struct
kishino 12:0254eaccfda2 18 {
kishino 12:0254eaccfda2 19 unsigned char buf[MEMPOOL_BLOCK_SIZE];
kishino 12:0254eaccfda2 20 }tagMEMPOOL_BLOCK_T;
kishino 12:0254eaccfda2 21
kishino 12:0254eaccfda2 22 #define MAX_SOCKET_ID 5
kishino 12:0254eaccfda2 23
kishino 12:0254eaccfda2 24 /** Connection information
kishino 12:0254eaccfda2 25 */
kishino 12:0254eaccfda2 26 typedef struct {
kishino 12:0254eaccfda2 27 CircBuffer<unsigned char> *recvbuf_p;
kishino 12:0254eaccfda2 28 bool is_connected;
kishino 12:0254eaccfda2 29 bool is_received;
kishino 12:0254eaccfda2 30 }tagCONNECT_INFO_T;
kishino 12:0254eaccfda2 31
kishino 12:0254eaccfda2 32 /** Wi-Fi security
kishino 12:0254eaccfda2 33 */
kishino 12:0254eaccfda2 34 typedef enum SECURITY {
kishino 12:0254eaccfda2 35 /** Securiry Open */
kishino 12:0254eaccfda2 36 e_SEC_OPEN = 0x00,
kishino 12:0254eaccfda2 37 /** Securiry WEP */
kishino 12:0254eaccfda2 38 e_SEC_WEP = 0x01,
kishino 12:0254eaccfda2 39 /** Securiry WPA-PSK(TKIP) */
kishino 12:0254eaccfda2 40 e_SEC_WPA_TKIP = 0x02,
kishino 12:0254eaccfda2 41 /** Securiry WPA2-PSK(AES) */
kishino 12:0254eaccfda2 42 e_SEC_WPA2_AES = 0x04,
kishino 12:0254eaccfda2 43 /** Securiry WPA2-PSK(TKIP/AES) */
kishino 12:0254eaccfda2 44 e_SEC_WPA2_MIXED = 0x06,
kishino 12:0254eaccfda2 45 /** Securiry WPA-PSK(AES) */
kishino 12:0254eaccfda2 46 e_SEC_WPA_AES = 0x07
kishino 12:0254eaccfda2 47 }E_SECURITY;
kishino 12:0254eaccfda2 48
kishino 12:0254eaccfda2 49 /** Wi-Fi Network type
kishino 12:0254eaccfda2 50 */
kishino 12:0254eaccfda2 51 typedef enum NETWORK_TYPE {
kishino 12:0254eaccfda2 52 /** Infrastructure */
kishino 12:0254eaccfda2 53 e_INFRA = 0,
kishino 12:0254eaccfda2 54 /** Adhoc */
kishino 12:0254eaccfda2 55 e_ADHOC = 1
kishino 12:0254eaccfda2 56 }E_NETWORK_TYPE;
kishino 12:0254eaccfda2 57
kishino 12:0254eaccfda2 58 /** Wi-Fi status
kishino 12:0254eaccfda2 59 */
kishino 12:0254eaccfda2 60 typedef enum WIFI_STATUS {
kishino 12:0254eaccfda2 61 /** Wi-Fi OFF */
kishino 12:0254eaccfda2 62 e_STATUS_OFF = 0,
kishino 12:0254eaccfda2 63 /** No network */
kishino 12:0254eaccfda2 64 e_NO_NETWORK,
kishino 12:0254eaccfda2 65 /** Connected to AP (STA mode) */
kishino 12:0254eaccfda2 66 e_STA_JOINED,
kishino 12:0254eaccfda2 67 /** Started on AP mode */
kishino 12:0254eaccfda2 68 e_AP_STARTED
kishino 12:0254eaccfda2 69 }E_WIFI_STATUS;
kishino 12:0254eaccfda2 70
kishino 12:0254eaccfda2 71 /** GEN_FW_VER_GET_REQ Command */
kishino 12:0254eaccfda2 72 typedef struct
kishino 12:0254eaccfda2 73 {
kishino 12:0254eaccfda2 74 unsigned char cmd_sid;
kishino 12:0254eaccfda2 75 unsigned char seq;
kishino 12:0254eaccfda2 76 }tagGEN_FW_VER_GET_REQ_T;
kishino 12:0254eaccfda2 77
kishino 12:0254eaccfda2 78 /** SNIC_INIT_REQ */
kishino 12:0254eaccfda2 79 typedef struct
kishino 12:0254eaccfda2 80 {
kishino 12:0254eaccfda2 81 unsigned char cmd_sid;
kishino 12:0254eaccfda2 82 unsigned char seq;
kishino 12:0254eaccfda2 83 unsigned short buf_size;
kishino 12:0254eaccfda2 84 }tagSNIC_INIT_REQ_T;
kishino 12:0254eaccfda2 85
kishino 12:0254eaccfda2 86 /** SNIC_TCP_CREATE_SOCKET_REQ */
kishino 12:0254eaccfda2 87 typedef struct
kishino 12:0254eaccfda2 88 {
kishino 12:0254eaccfda2 89 unsigned char cmd_sid;
kishino 12:0254eaccfda2 90 unsigned char seq;
kishino 12:0254eaccfda2 91 unsigned char bind;
kishino 13:53e6471d5753 92 unsigned char local_addr[4];
kishino 13:53e6471d5753 93 unsigned char local_port[2];
kishino 12:0254eaccfda2 94 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
kishino 12:0254eaccfda2 95
kishino 13:53e6471d5753 96 /** SNIC_TCP_SEND_FROM_SOCKET_REQ */
kishino 13:53e6471d5753 97 typedef struct
kishino 13:53e6471d5753 98 {
kishino 13:53e6471d5753 99 unsigned char cmd_sid;
kishino 13:53e6471d5753 100 unsigned char seq;
kishino 13:53e6471d5753 101 unsigned char socket_id;
kishino 13:53e6471d5753 102 unsigned char option;
kishino 13:53e6471d5753 103 unsigned char payload_len[2];
kishino 13:53e6471d5753 104 }tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T;
kishino 13:53e6471d5753 105
kishino 12:0254eaccfda2 106 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
kishino 12:0254eaccfda2 107 typedef struct
kishino 12:0254eaccfda2 108 {
kishino 12:0254eaccfda2 109 unsigned char cmd_sid;
kishino 12:0254eaccfda2 110 unsigned char seq;
kishino 12:0254eaccfda2 111 unsigned char socket_id;
kishino 12:0254eaccfda2 112 unsigned char remote_addr[4];
kishino 12:0254eaccfda2 113 unsigned char remote_port[2];
kishino 12:0254eaccfda2 114 unsigned char recv_bufsize[2];
kishino 13:53e6471d5753 115 unsigned char timeout;
kishino 12:0254eaccfda2 116 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
kishino 12:0254eaccfda2 117
kishino 12:0254eaccfda2 118 /** WIFI_ON_REQ Command */
kishino 12:0254eaccfda2 119 typedef struct
kishino 12:0254eaccfda2 120 {
kishino 12:0254eaccfda2 121 unsigned char cmd_sid;
kishino 12:0254eaccfda2 122 unsigned char seq;
kishino 12:0254eaccfda2 123 char country[COUNTRYC_CODE_LENTH];
kishino 12:0254eaccfda2 124 }tagWIFI_ON_REQ_T;
kishino 12:0254eaccfda2 125
kishino 12:0254eaccfda2 126 /** WIFI_OFF_REQ Command */
kishino 12:0254eaccfda2 127 typedef struct
kishino 12:0254eaccfda2 128 {
kishino 12:0254eaccfda2 129 unsigned char cmd_sid;
kishino 12:0254eaccfda2 130 unsigned char seq;
kishino 12:0254eaccfda2 131 }tagWIFI_OFF_REQ_T;
kishino 12:0254eaccfda2 132
kishino 12:0254eaccfda2 133 /** WIFI_DISCONNECT_REQ Command */
kishino 12:0254eaccfda2 134 typedef struct
kishino 12:0254eaccfda2 135 {
kishino 12:0254eaccfda2 136 unsigned char cmd_sid;
kishino 12:0254eaccfda2 137 unsigned char seq;
kishino 12:0254eaccfda2 138 }tagWIFI_DISCONNECT_REQ_T;
kishino 12:0254eaccfda2 139
kishino 12:0254eaccfda2 140 /** WIFI_GET_STA_RSSI_REQ Command */
kishino 12:0254eaccfda2 141 typedef struct
kishino 12:0254eaccfda2 142 {
kishino 12:0254eaccfda2 143 unsigned char cmd_sid;
kishino 12:0254eaccfda2 144 unsigned char seq;
kishino 12:0254eaccfda2 145 }tagWIFI_GET_STA_RSSI_REQ_T;
kishino 12:0254eaccfda2 146
kishino 12:0254eaccfda2 147 /** WIFI_GET_STATUS_REQ Command */
kishino 12:0254eaccfda2 148 typedef struct
kishino 12:0254eaccfda2 149 {
kishino 12:0254eaccfda2 150 unsigned char cmd_sid;
kishino 12:0254eaccfda2 151 unsigned char seq;
kishino 12:0254eaccfda2 152 unsigned char interface;
kishino 12:0254eaccfda2 153 }tagWIFI_GET_STATUS_REQ_T;
kishino 12:0254eaccfda2 154
kishino 12:0254eaccfda2 155 /** WIFI_SCAN_REQ Command */
kishino 12:0254eaccfda2 156 typedef struct
kishino 12:0254eaccfda2 157 {
kishino 12:0254eaccfda2 158 unsigned char cmd_sid;
kishino 12:0254eaccfda2 159 unsigned char seq;
kishino 12:0254eaccfda2 160 unsigned char scan_type;
kishino 12:0254eaccfda2 161 unsigned char bss_type;
kishino 12:0254eaccfda2 162 unsigned char bssid[BSSID_MAC_LENTH];
kishino 12:0254eaccfda2 163 unsigned char chan_list;
kishino 12:0254eaccfda2 164 unsigned char ssid[SSID_MAX_LENGTH+1];
kishino 12:0254eaccfda2 165 }tagWIFI_SCAN_REQ_T;
kishino 12:0254eaccfda2 166
kishino 12:0254eaccfda2 167 /** C_SNIC_Core class
kishino 12:0254eaccfda2 168 */
kishino 12:0254eaccfda2 169 class C_SNIC_Core
kishino 12:0254eaccfda2 170 {
kishino 12:0254eaccfda2 171
kishino 12:0254eaccfda2 172 public:
kishino 12:0254eaccfda2 173 C_SNIC_UartCommandManager mUartCommand;
kishino 12:0254eaccfda2 174
kishino 12:0254eaccfda2 175 /** Get buffer for command from memory pool.
kishino 12:0254eaccfda2 176 @return Pointer of buffer
kishino 12:0254eaccfda2 177 */
kishino 12:0254eaccfda2 178 tagMEMPOOL_BLOCK_T *getAlocCmdBuf();
kishino 12:0254eaccfda2 179
kishino 12:0254eaccfda2 180 /** Release buffer to memory pool.
kishino 12:0254eaccfda2 181 @param buf_p Pointer of buffer
kishino 12:0254eaccfda2 182 */
kishino 12:0254eaccfda2 183 void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 12:0254eaccfda2 184
kishino 12:0254eaccfda2 185 /** Initialize UART
kishino 12:0254eaccfda2 186 */
kishino 12:0254eaccfda2 187 int initUart( PinName tx, PinName rx, int baud );
kishino 12:0254eaccfda2 188
kishino 12:0254eaccfda2 189 /** Send data to UART
kishino 12:0254eaccfda2 190 @param len Length of send data
kishino 12:0254eaccfda2 191 @param data Pointer of send data
kishino 12:0254eaccfda2 192 @return 0:success/other:fail
kishino 12:0254eaccfda2 193 */
kishino 12:0254eaccfda2 194 int sendUart( unsigned int len, unsigned char *data );
kishino 12:0254eaccfda2 195
kishino 12:0254eaccfda2 196 /** Preparation of the UART command
kishino 12:0254eaccfda2 197 @param cmd_id UART Command ID
kishino 12:0254eaccfda2 198 @param cmd_sid UART Command SubID
kishino 12:0254eaccfda2 199 @param req_buf_p Pointer of UART request buffer
kishino 12:0254eaccfda2 200 @param req_buf_len Length of UART request buffer
kishino 12:0254eaccfda2 201 @param response_buf_p Pointer of UART response buffer
kishino 12:0254eaccfda2 202 @param command_p Pointer of UART command[output]
kishino 12:0254eaccfda2 203 @return Length of UART command.
kishino 12:0254eaccfda2 204 */
kishino 12:0254eaccfda2 205 unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
kishino 12:0254eaccfda2 206 , unsigned char *req_buf_p, unsigned int req_buf_len
kishino 12:0254eaccfda2 207 , unsigned char *response_buf_p, unsigned char *command_p );
kishino 12:0254eaccfda2 208
kishino 12:0254eaccfda2 209 /**
kishino 12:0254eaccfda2 210 Get pointer of connection information.
kishino 12:0254eaccfda2 211 @param socket_id Socket ID
kishino 12:0254eaccfda2 212 @return The pointer of connection information
kishino 12:0254eaccfda2 213 */
kishino 12:0254eaccfda2 214 tagCONNECT_INFO_T *getConnectInfo( int socket_id );
kishino 12:0254eaccfda2 215
kishino 12:0254eaccfda2 216 /** Get an instance of the C_SNIC_Core class.
kishino 12:0254eaccfda2 217 @return Instance of the C_SNIC_Core class
kishino 12:0254eaccfda2 218 @note Please do not create an instance in the default constructor this class.
kishino 12:0254eaccfda2 219 Please use this method when you want to get an instance.
kishino 12:0254eaccfda2 220 */
kishino 12:0254eaccfda2 221 static C_SNIC_Core *getInstance();
kishino 12:0254eaccfda2 222
kishino 12:0254eaccfda2 223 protected:
kishino 12:0254eaccfda2 224 static C_SNIC_Core *mInstance_p;
kishino 12:0254eaccfda2 225 Thread *mUartRecvThread_p;
kishino 12:0254eaccfda2 226 RawSerial *mUart_p;
kishino 12:0254eaccfda2 227 Mutex mUartMutex;
kishino 12:0254eaccfda2 228 // DigitalInOut mModuleReset;
kishino 12:0254eaccfda2 229
kishino 12:0254eaccfda2 230 private:
kishino 12:0254eaccfda2 231 /** MemoryPool for payload of UART response */
kishino 12:0254eaccfda2 232 MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload;
kishino 12:0254eaccfda2 233
kishino 12:0254eaccfda2 234 /** Socket buffer */
kishino 12:0254eaccfda2 235 tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1];
kishino 12:0254eaccfda2 236
kishino 12:0254eaccfda2 237 /** Constructor
kishino 12:0254eaccfda2 238 */
kishino 12:0254eaccfda2 239 C_SNIC_Core();
kishino 12:0254eaccfda2 240
kishino 12:0254eaccfda2 241 /** Receiving thread of UART
kishino 12:0254eaccfda2 242 */
kishino 12:0254eaccfda2 243 static void uartRecvThread( void const *args_p );
kishino 12:0254eaccfda2 244 };
kishino 12:0254eaccfda2 245 }
kishino 12:0254eaccfda2 246
kishino 12:0254eaccfda2 247 #endif