cc
Embed:
(wiki syntax)
Show/hide line numbers
SPWFSA01.h
00001 /* SPWFInterface Example 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SPWFSA01_H 00018 #define SPWFSA01_H 00019 00020 #include "ATParser.h" 00021 00022 enum CertType_t { 00023 RAM_CA_ROOT_CERT =0, // store CA root certicate in RAM 00024 RAM_CLIENT_CERT, 00025 RAM_CLIENT_PRIV_KEY, 00026 FLASH_CA_ROOT_CERT, // store CA root certicate in FLASH 00027 FLASH_CLIENT_CERT, 00028 FLASH_CLIENT_PRIV_KEY, 00029 RAM_DOMAIN, // store secure server domain name in RAM 00030 FLASH_DOMAIN, // store secure server domain name in RAM 00031 ALL // clear all the CERT and DOMAIN from flash 00032 }; 00033 00034 /** SPWFSA01Interface class. 00035 This is an interface to a SPWFSA01 module. 00036 */ 00037 class SPWFSA01 00038 { 00039 public: 00040 00041 SPWFSA01(PinName tx, PinName rx, PinName reset=NC, PinName wakeup=NC, bool debug=false); 00042 00043 /** 00044 * Init the SPWFSA01 00045 * 00046 * @param mode mode in which to startup 00047 * @return true only if SPWFSA01 has started up correctly 00048 */ 00049 bool startup(int mode); 00050 00051 void waitSPWFReady(void); 00052 /** 00053 * Reset SPWFSA01 00054 * 00055 * @return true only if SPWFSA01 resets successfully 00056 */ 00057 bool reset(void); 00058 00059 bool hw_reset(void); 00060 00061 /** 00062 * Enable/Disable DHCP 00063 * 00064 * @param mode mode of DHCP 2-softAP, 1-on, 0-off 00065 * @return true only if SPWFSA01 enables/disables DHCP successfully 00066 */ 00067 bool dhcp(int mode); 00068 00069 /** 00070 * Connect SPWFSA01 to AP 00071 * 00072 * @param ap the name of the AP 00073 * @param passPhrase the password of AP 00074 * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open) 00075 * @return true only if SPWFSA01 is connected successfully 00076 */ 00077 bool connect(const char *ap, const char *passPhrase, int securityMode); 00078 00079 /** 00080 * Disconnect SPWFSA01 from AP 00081 * 00082 * @return true only if SPWFSA01 is disconnected successfully 00083 */ 00084 bool disconnect(void); 00085 00086 /** 00087 * Get the IP address of SPWFSA01 00088 * 00089 * @return null-teriminated IP address or null if no IP address is assigned 00090 */ 00091 const char *getIPAddress(void); 00092 00093 /** 00094 * Get the MAC address of SPWFSA01 00095 * 00096 * @return null-terminated MAC address or null if no MAC address is assigned 00097 */ 00098 const char *getMACAddress(void); 00099 00100 /** 00101 * Check if SPWFSA01 is conenected 00102 * 00103 * @return true only if the chip has an IP address 00104 */ 00105 bool isConnected(void); 00106 00107 /** 00108 * Open a socketed connection 00109 * 00110 * @param type the type of socket to open "u" (UDP) or "t" (TCP) 00111 * @param id id to get the new socket number, valid 0-7 00112 * @param port port to open connection with 00113 * @param addr the IP address of the destination 00114 * @return true only if socket opened successfully 00115 */ 00116 bool open(const char *type, int* id, const char* addr, int port); 00117 00118 /** 00119 * Sends data to an open socket 00120 * 00121 * @param id id of socket to send to 00122 * @param data data to be sent 00123 * @param amount amount of data to be sent - max 1024 00124 * @return true only if data sent successfully 00125 */ 00126 bool send(int id, const void *data, uint32_t amount); 00127 00128 /** 00129 * Receives data from an open socket 00130 * 00131 * @param id id to receive from 00132 * @param data placeholder for returned information 00133 * @param amount number of bytes to be received 00134 * @return the number of bytes received 00135 */ 00136 int32_t recv(int id, void *data, uint32_t amount); 00137 00138 /** 00139 * Closes a socket 00140 * 00141 * @param id id of socket to close, valid only 0-4 00142 * @return true only if socket is closed successfully 00143 */ 00144 bool close(int id); 00145 00146 00147 /** 00148 * Checks if data is available 00149 */ 00150 bool readable(); 00151 00152 /** 00153 * Checks if data can be written 00154 */ 00155 bool writeable(); 00156 00157 int settime(time_t ctTime); 00158 int gettime(time_t *ctTime); 00159 00160 int32_t setTLScertificate(char * cert, unsigned int size, CertType_t type); 00161 int32_t setTLSSRVdomain(char * cert, CertType_t type); 00162 int32_t cleanTLScertificate(CertType_t type); 00163 00164 00165 private: 00166 BufferedSerial _serial; 00167 ATParser _parser; 00168 DigitalInOut _wakeup; 00169 DigitalInOut _reset; 00170 char _ip_buffer[16]; 00171 char _mac_buffer[18]; 00172 bool dbg_on; 00173 // int _timeout; // FIXME LICIO we have "virtual" socket tmo, module socket tmo, 00174 // AT parser tmo, recv/send tmo, actually used the NetworksocketAPI socket tmo 00175 unsigned int _recv_timeout; // see SO_RCVTIMEO setsockopt 00176 unsigned int _send_timeout; // see SO_SNDTIMEO setsockopt 00177 unsigned int socket_closed; 00178 }; 00179 00180 #endif //SPWFSA01_H
Generated on Tue Jul 25 2023 08:32:12 by 1.7.2