DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
CC3100.hpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 *******************************************************************************/ 00032 00033 #ifndef CC3100_HPP 00034 #define CC3100_HPP 00035 00036 #include <stdint.h> 00037 #include <stddef.h> 00038 #include <ctime> 00039 #include <string> 00040 #include <mbed-os/drivers/DigitalOut.h> 00041 #include <mbed-os/drivers/SPI.h> 00042 #include <mbed-os/features/netsocket/NetworkStack.h> 00043 #include <mbed-os/features/netsocket/WiFiInterface.h> 00044 00045 /// CC3100 Wi-Fi station interface for mbed using SPI. 00046 class CC3100 : public NetworkStack, public WiFiInterface { 00047 public: 00048 /// SPI bus interface. 00049 class SPI { 00050 public: 00051 SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel); 00052 00053 void transfer(const uint8_t * txData, size_t dataSize, uint8_t * rxData); 00054 00055 private: 00056 mbed::SPI spi; 00057 mbed::DigitalOut cs; 00058 }; 00059 00060 /// CC3100 device state. 00061 enum State { 00062 Stopped, 00063 Disconnected, 00064 ConnectedWithoutIp, 00065 Connected, 00066 Pinging 00067 }; 00068 00069 /// @brief 00070 /// Result code occurring when the CC3100 is in an invalid state to perform 00071 /// an operation. 00072 static const int invalidState = -1; 00073 00074 /// Retrieve the singleton instance. 00075 static CC3100 & instance(); 00076 00077 /// Current state of the CC3100. 00078 State state() const; 00079 00080 /// Start the CC3100 so that nework functionality is available. 00081 int start(); 00082 00083 /// Stop the CC3100 and enter a low power state. 00084 int stop(); 00085 00086 /// Update the networking stack. Should be called regularly to dispatch events. 00087 void update(); 00088 00089 /// Set the current date and time. 00090 int setDateTime(const std::tm & dateTime); 00091 00092 // WiFi station functionality 00093 00094 virtual int set_credentials(const char * ssid, const char * pass, 00095 nsapi_security_t security = NSAPI_SECURITY_NONE); 00096 00097 virtual int set_channel(uint8_t channel) { 00098 this->channel = channel; 00099 return 0; 00100 } 00101 00102 virtual int8_t get_rssi() { return 0; } // Not implemented 00103 00104 virtual int connect(const char * ssid, const char * pass, 00105 nsapi_security_t security = NSAPI_SECURITY_NONE, 00106 uint8_t channel = 0); 00107 00108 virtual int connect() { 00109 return connect(ssid.c_str(), pass.c_str(), security, channel); 00110 } 00111 00112 int connect(const char * ssid, const char * username, const char * password); 00113 00114 virtual int disconnect(); 00115 00116 virtual int scan(WiFiAccessPoint * res, unsigned count) { 00117 // Not implemented 00118 return invalidState; 00119 } 00120 00121 // Network functionality 00122 virtual const char * get_ip_address() { return NULL; } // Not implemented 00123 00124 virtual int gethostbyname(const char * host, SocketAddress * address, 00125 nsapi_version_t version = NSAPI_UNSPEC); 00126 00127 int ping(const SocketAddress & address); 00128 00129 virtual NetworkStack * get_stack() { return this; } 00130 00131 // Socket functionality 00132 00133 virtual int socket_open(nsapi_socket_t * handle, nsapi_protocol_t proto); 00134 00135 int socket_set_cert_path(nsapi_socket_t handle, const char * certPath); 00136 00137 virtual int socket_close(nsapi_socket_t handle); 00138 00139 virtual int socket_bind(nsapi_socket_t handle, const SocketAddress & address); 00140 00141 virtual int socket_listen(nsapi_socket_t handle, int backlog); 00142 00143 virtual int socket_connect(nsapi_socket_t handle, 00144 const SocketAddress & address); 00145 00146 virtual int socket_accept(nsapi_socket_t server, nsapi_socket_t * handle, 00147 SocketAddress * address = 0) { 00148 // Not implemented 00149 return invalidState; 00150 } 00151 00152 virtual int socket_send(nsapi_socket_t handle, const void * data, 00153 unsigned size); 00154 00155 virtual int socket_recv(nsapi_socket_t handle, void * data, unsigned size); 00156 00157 virtual int socket_sendto(nsapi_socket_t handle, 00158 const SocketAddress & address, const void * data, 00159 unsigned size) { 00160 // Not implemented 00161 return invalidState; 00162 } 00163 00164 virtual int socket_recvfrom(nsapi_socket_t handle, SocketAddress * address, 00165 void * buffer, unsigned size) { 00166 // Not implemented 00167 return invalidState; 00168 } 00169 00170 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), 00171 void * data) { 00172 // Not implemented 00173 } 00174 00175 private: 00176 SPI spi; 00177 00178 std::string ssid; 00179 std::string pass; 00180 nsapi_security_t security; 00181 uint8_t channel; 00182 00183 CC3100(); 00184 00185 // Uncopyable 00186 CC3100(const CC3100 &); 00187 const CC3100 & operator=(const CC3100 &); 00188 }; 00189 00190 #endif
Generated on Tue Jul 12 2022 12:06:48 by 1.7.2