customized SNICInterface

Dependents:   MurataTypeYD_Ping

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Thu Mar 27 06:52:04 2014 +0000
Revision:
20:dd736d328de6
Child:
21:dda155fe5048
Change to folder from library.

Who changed what in which revision?

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