cc

Dependencies:   ATParser

Committer:
mapellil
Date:
Mon Jan 02 14:46:40 2017 +0000
Revision:
25:6b79352bc1fa
Parent:
24:419285201dba
Child:
27:0dc1402f42a9
Added TLS secure socket API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:9e5d98ceea74 1 /* SPWFInterface Example
mridup 0:9e5d98ceea74 2 * Copyright (c) 2015 ARM Limited
mridup 0:9e5d98ceea74 3 *
mridup 0:9e5d98ceea74 4 * Licensed under the Apache License, Version 2.0 (the "License");
mridup 0:9e5d98ceea74 5 * you may not use this file except in compliance with the License.
mridup 0:9e5d98ceea74 6 * You may obtain a copy of the License at
mridup 0:9e5d98ceea74 7 *
mridup 0:9e5d98ceea74 8 * http://www.apache.org/licenses/LICENSE-2.0
mridup 0:9e5d98ceea74 9 *
mridup 0:9e5d98ceea74 10 * Unless required by applicable law or agreed to in writing, software
mridup 0:9e5d98ceea74 11 * distributed under the License is distributed on an "AS IS" BASIS,
mridup 0:9e5d98ceea74 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mridup 0:9e5d98ceea74 13 * See the License for the specific language governing permissions and
mridup 0:9e5d98ceea74 14 * limitations under the License.
mridup 0:9e5d98ceea74 15 */
mridup 0:9e5d98ceea74 16
mridup 0:9e5d98ceea74 17 #ifndef SPWFSA01_H
mridup 0:9e5d98ceea74 18 #define SPWFSA01_H
mridup 0:9e5d98ceea74 19
mridup 0:9e5d98ceea74 20 #include "ATParser.h"
mridup 0:9e5d98ceea74 21
mapellil 25:6b79352bc1fa 22 enum CertType_t {
mapellil 25:6b79352bc1fa 23 RAM_CA_ROOT_CERT =0, // store CA root certicate in RAM
mapellil 25:6b79352bc1fa 24 RAM_CLIENT_CERT,
mapellil 25:6b79352bc1fa 25 RAM_CLIENT_PRIV_KEY,
mapellil 25:6b79352bc1fa 26 FLASH_CA_ROOT_CERT, // store CA root certicate in FLASH
mapellil 25:6b79352bc1fa 27 FLASH_CLIENT_CERT,
mapellil 25:6b79352bc1fa 28 FLASH_CLIENT_PRIV_KEY,
mapellil 25:6b79352bc1fa 29 RAM_DOMAIN, // store secure server domain name in RAM
mapellil 25:6b79352bc1fa 30 FLASH_DOMAIN, // store secure server domain name in RAM
mapellil 25:6b79352bc1fa 31 ALL // clear all the CERT and DOMAIN from flash
mapellil 25:6b79352bc1fa 32 };
mapellil 25:6b79352bc1fa 33
mridup 0:9e5d98ceea74 34 /** SPWFSA01Interface class.
mridup 0:9e5d98ceea74 35 This is an interface to a SPWFSA01 module.
mridup 0:9e5d98ceea74 36 */
mridup 0:9e5d98ceea74 37 class SPWFSA01
mridup 0:9e5d98ceea74 38 {
mridup 0:9e5d98ceea74 39 public:
mapellil 24:419285201dba 40
mapellil 24:419285201dba 41 SPWFSA01(PinName tx, PinName rx, PinName reset=NC, PinName wakeup=NC, bool debug=false);
mapellil 24:419285201dba 42
mridup 0:9e5d98ceea74 43 /**
mridup 0:9e5d98ceea74 44 * Init the SPWFSA01
mridup 0:9e5d98ceea74 45 *
mridup 0:9e5d98ceea74 46 * @param mode mode in which to startup
mridup 0:9e5d98ceea74 47 * @return true only if SPWFSA01 has started up correctly
mridup 0:9e5d98ceea74 48 */
mridup 0:9e5d98ceea74 49 bool startup(int mode);
mridup 0:9e5d98ceea74 50
mridup 0:9e5d98ceea74 51 void waitSPWFReady(void);
mridup 0:9e5d98ceea74 52 /**
mridup 0:9e5d98ceea74 53 * Reset SPWFSA01
mridup 0:9e5d98ceea74 54 *
mridup 0:9e5d98ceea74 55 * @return true only if SPWFSA01 resets successfully
mridup 0:9e5d98ceea74 56 */
mridup 0:9e5d98ceea74 57 bool reset(void);
mridup 0:9e5d98ceea74 58
mridup 0:9e5d98ceea74 59 bool hw_reset(void);
mridup 0:9e5d98ceea74 60
mridup 0:9e5d98ceea74 61 /**
mridup 0:9e5d98ceea74 62 * Enable/Disable DHCP
mridup 0:9e5d98ceea74 63 *
mridup 5:f17d6351e942 64 * @param mode mode of DHCP 2-softAP, 1-on, 0-off
mridup 0:9e5d98ceea74 65 * @return true only if SPWFSA01 enables/disables DHCP successfully
mridup 0:9e5d98ceea74 66 */
mridup 5:f17d6351e942 67 bool dhcp(int mode);
mridup 0:9e5d98ceea74 68
mridup 0:9e5d98ceea74 69 /**
mridup 0:9e5d98ceea74 70 * Connect SPWFSA01 to AP
mridup 0:9e5d98ceea74 71 *
mridup 0:9e5d98ceea74 72 * @param ap the name of the AP
mridup 0:9e5d98ceea74 73 * @param passPhrase the password of AP
mridup 0:9e5d98ceea74 74 * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open)
mridup 0:9e5d98ceea74 75 * @return true only if SPWFSA01 is connected successfully
mridup 0:9e5d98ceea74 76 */
mridup 0:9e5d98ceea74 77 bool connect(const char *ap, const char *passPhrase, int securityMode);
mridup 0:9e5d98ceea74 78
mridup 0:9e5d98ceea74 79 /**
mridup 0:9e5d98ceea74 80 * Disconnect SPWFSA01 from AP
mridup 0:9e5d98ceea74 81 *
mridup 0:9e5d98ceea74 82 * @return true only if SPWFSA01 is disconnected successfully
mridup 0:9e5d98ceea74 83 */
mridup 0:9e5d98ceea74 84 bool disconnect(void);
mridup 0:9e5d98ceea74 85
mridup 0:9e5d98ceea74 86 /**
mridup 0:9e5d98ceea74 87 * Get the IP address of SPWFSA01
mridup 0:9e5d98ceea74 88 *
mridup 0:9e5d98ceea74 89 * @return null-teriminated IP address or null if no IP address is assigned
mridup 0:9e5d98ceea74 90 */
mridup 0:9e5d98ceea74 91 const char *getIPAddress(void);
mridup 0:9e5d98ceea74 92
mridup 0:9e5d98ceea74 93 /**
mridup 0:9e5d98ceea74 94 * Get the MAC address of SPWFSA01
mridup 0:9e5d98ceea74 95 *
mridup 0:9e5d98ceea74 96 * @return null-terminated MAC address or null if no MAC address is assigned
mridup 0:9e5d98ceea74 97 */
mridup 0:9e5d98ceea74 98 const char *getMACAddress(void);
mridup 0:9e5d98ceea74 99
mridup 0:9e5d98ceea74 100 /**
mridup 0:9e5d98ceea74 101 * Check if SPWFSA01 is conenected
mridup 0:9e5d98ceea74 102 *
mridup 0:9e5d98ceea74 103 * @return true only if the chip has an IP address
mridup 0:9e5d98ceea74 104 */
mridup 0:9e5d98ceea74 105 bool isConnected(void);
mridup 0:9e5d98ceea74 106
mridup 0:9e5d98ceea74 107 /**
mridup 0:9e5d98ceea74 108 * Open a socketed connection
mridup 0:9e5d98ceea74 109 *
mridup 5:f17d6351e942 110 * @param type the type of socket to open "u" (UDP) or "t" (TCP)
mridup 5:f17d6351e942 111 * @param id id to get the new socket number, valid 0-7
mridup 0:9e5d98ceea74 112 * @param port port to open connection with
mridup 0:9e5d98ceea74 113 * @param addr the IP address of the destination
mridup 0:9e5d98ceea74 114 * @return true only if socket opened successfully
mridup 0:9e5d98ceea74 115 */
mridup 3:2af9df1068a5 116 bool open(const char *type, int* id, const char* addr, int port);
mridup 0:9e5d98ceea74 117
mridup 0:9e5d98ceea74 118 /**
mridup 0:9e5d98ceea74 119 * Sends data to an open socket
mridup 0:9e5d98ceea74 120 *
mridup 0:9e5d98ceea74 121 * @param id id of socket to send to
mridup 0:9e5d98ceea74 122 * @param data data to be sent
mridup 0:9e5d98ceea74 123 * @param amount amount of data to be sent - max 1024
mridup 0:9e5d98ceea74 124 * @return true only if data sent successfully
mridup 0:9e5d98ceea74 125 */
mridup 0:9e5d98ceea74 126 bool send(int id, const void *data, uint32_t amount);
mridup 0:9e5d98ceea74 127
mridup 0:9e5d98ceea74 128 /**
mridup 0:9e5d98ceea74 129 * Receives data from an open socket
mridup 0:9e5d98ceea74 130 *
mridup 0:9e5d98ceea74 131 * @param id id to receive from
mridup 0:9e5d98ceea74 132 * @param data placeholder for returned information
mridup 0:9e5d98ceea74 133 * @param amount number of bytes to be received
mridup 0:9e5d98ceea74 134 * @return the number of bytes received
mridup 0:9e5d98ceea74 135 */
mridup 0:9e5d98ceea74 136 int32_t recv(int id, void *data, uint32_t amount);
mridup 0:9e5d98ceea74 137
mridup 0:9e5d98ceea74 138 /**
mridup 0:9e5d98ceea74 139 * Closes a socket
mridup 0:9e5d98ceea74 140 *
mridup 0:9e5d98ceea74 141 * @param id id of socket to close, valid only 0-4
mridup 0:9e5d98ceea74 142 * @return true only if socket is closed successfully
mridup 0:9e5d98ceea74 143 */
mridup 0:9e5d98ceea74 144 bool close(int id);
mridup 0:9e5d98ceea74 145
mridup 0:9e5d98ceea74 146
mridup 0:9e5d98ceea74 147 /**
mridup 0:9e5d98ceea74 148 * Checks if data is available
mridup 0:9e5d98ceea74 149 */
mridup 0:9e5d98ceea74 150 bool readable();
mridup 0:9e5d98ceea74 151
mridup 0:9e5d98ceea74 152 /**
mridup 0:9e5d98ceea74 153 * Checks if data can be written
mridup 0:9e5d98ceea74 154 */
mridup 0:9e5d98ceea74 155 bool writeable();
mridup 0:9e5d98ceea74 156
mapellil 25:6b79352bc1fa 157 int settime(time_t ctTime);
mapellil 25:6b79352bc1fa 158
mapellil 25:6b79352bc1fa 159 int32_t setTLScertificate(char * cert, unsigned int size, CertType_t type);
mapellil 25:6b79352bc1fa 160 int32_t setTLSSRVdomain(char * cert, CertType_t type);
mapellil 25:6b79352bc1fa 161 int32_t cleanTLScertificate(CertType_t type);
mapellil 25:6b79352bc1fa 162
mapellil 25:6b79352bc1fa 163
mridup 0:9e5d98ceea74 164 private:
mridup 0:9e5d98ceea74 165 BufferedSerial _serial;
mridup 0:9e5d98ceea74 166 ATParser _parser;
mridup 0:9e5d98ceea74 167 DigitalInOut _wakeup;
mapellil 24:419285201dba 168 DigitalInOut _reset;
mridup 0:9e5d98ceea74 169 char _ip_buffer[16];
mridup 0:9e5d98ceea74 170 char _mac_buffer[18];
mridup 13:f21e4e73bbb6 171 bool dbg_on;
mapellil 24:419285201dba 172 // int _timeout; // FIXME LICIO we have "virtual" socket tmo, module socket tmo,
mapellil 24:419285201dba 173 // AT parser tmo, recv/send tmo, actually used the NetworksocketAPI socket tmo
mapellil 24:419285201dba 174 unsigned int _recv_timeout; // see SO_RCVTIMEO setsockopt
mapellil 24:419285201dba 175 unsigned int _send_timeout; // see SO_SNDTIMEO setsockopt
mapellil 24:419285201dba 176 unsigned int socket_closed;
mridup 0:9e5d98ceea74 177 };
mridup 0:9e5d98ceea74 178
mapellil 24:419285201dba 179 #endif //SPWFSA01_H