cliff
Fork of WizFi250Interface by
Embed:
(wiki syntax)
Show/hide line numbers
WizFi250Interface.h
00001 /* WizFi250 implementation of NetworkInterfaceAPI 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 WIZFI250_INTERFACE_H 00018 #define WIZFI250_INTERFACE_H 00019 00020 #include "mbed.h" 00021 #include "WizFi250.h" 00022 00023 #define WIZFI250_SOCKET_COUNT 8 00024 00025 /** WizFi250Interface class 00026 * Implementation of the NetworkStack for the WizFi250 00027 */ 00028 class WizFi250Interface : public NetworkStack, public WiFiInterface 00029 { 00030 public: 00031 WizFi250Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud=115200 ); 00032 00033 virtual int connect(); 00034 00035 virtual int connect( 00036 const char *ssid, 00037 const char *pass, 00038 nsapi_security_t security = NSAPI_SECURITY_NONE, 00039 uint8_t channel = 0); 00040 00041 /** Stop the interface 00042 * @return 0 on success, negative on failure 00043 */ 00044 00045 virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); 00046 00047 virtual int set_channel(uint8_t channel); 00048 00049 virtual int disconnect(); 00050 00051 /** Get the internally stored IP address 00052 * @return IP address of the interface or null if not yet connected 00053 */ 00054 virtual const char *get_ip_address(); 00055 00056 /** Get the internally stored MAC address 00057 * @return MAC address of the interface 00058 */ 00059 virtual const char *get_mac_address(); 00060 00061 virtual const char *get_gateway() { }; 00062 00063 virtual const char *get_netmask() { }; 00064 00065 virtual int8_t get_rssi() { }; 00066 00067 00068 virtual int scan(WiFiAccessPoint *res, unsigned count) { }; 00069 00070 using NetworkInterface::gethostbyname; 00071 using NetworkInterface::add_dns_server; 00072 00073 protected: 00074 /** Open a socket 00075 * @param handle Handle in which to store new socket 00076 * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP 00077 * @return 0 on success, negative on failure 00078 */ 00079 virtual int socket_open(void **handle, nsapi_protocol_t proto); 00080 00081 /** Close the socket 00082 * @param handle Socket handle 00083 * @return 0 on success, negative on failure 00084 * @note On failure, any memory associated with the socket must still 00085 * be cleaned up 00086 */ 00087 virtual int socket_close(void *handle); 00088 00089 /** Bind a server socket to a specific port 00090 * @param handle Socket handle 00091 * @param address Local address to listen for incoming connections on 00092 * @return 0 on success, negative on failure. 00093 */ 00094 virtual int socket_bind(void *handle, const SocketAddress &address); 00095 00096 /** Start listening for incoming connections 00097 * @param handle Socket handle 00098 * @param backlog Number of pending connections that can be queued up at any 00099 * one time [Default: 1] 00100 * @return 0 on success, negative on failure 00101 */ 00102 virtual int socket_listen(void *handle, int backlog); 00103 00104 /** Connects this TCP socket to the server 00105 * @param handle Socket handle 00106 * @param address SocketAddress to connect to 00107 * @return 0 on success, negative on failure 00108 */ 00109 virtual int socket_connect(void *handle, const SocketAddress &address); 00110 00111 /** Accept a new connection. 00112 * @param handle Handle in which to store new socket 00113 * @param server Socket handle to server to accept from 00114 * @return 0 on success, negative on failure 00115 * @note This call is not-blocking, if this call would block, must 00116 * immediately return NSAPI_ERROR_WOULD_WAIT 00117 */ 00118 //virtual int socket_accept(void **handle, void *server); 00119 virtual int socket_accept(void *handle, void **socket, SocketAddress *address); 00120 00121 /** Send data to the remote host 00122 * @param handle Socket handle 00123 * @param data The buffer to send to the host 00124 * @param size The length of the buffer to send 00125 * @return Number of written bytes on success, negative on failure 00126 * @note This call is not-blocking, if this call would block, must 00127 * immediately return NSAPI_ERROR_WOULD_WAIT 00128 */ 00129 virtual int socket_send(void *handle, const void *data, unsigned size); 00130 00131 /** Receive data from the remote host 00132 * @param handle Socket handle 00133 * @param data The buffer in which to store the data received from the host 00134 * @param size The maximum length of the buffer 00135 * @return Number of received bytes on success, negative on failure 00136 * @note This call is not-blocking, if this call would block, must 00137 * immediately return NSAPI_ERROR_WOULD_WAIT 00138 */ 00139 virtual int socket_recv(void *handle, void *data, unsigned size); 00140 00141 /** Send a packet to a remote endpoint 00142 * @param handle Socket handle 00143 * @param address The remote SocketAddress 00144 * @param data The packet to be sent 00145 * @param size The length of the packet to be sent 00146 * @return The number of written bytes on success, negative on failure 00147 * @note This call is not-blocking, if this call would block, must 00148 * immediately return NSAPI_ERROR_WOULD_WAIT 00149 */ 00150 virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); 00151 00152 /** Receive a packet from a remote endpoint 00153 * @param handle Socket handle 00154 * @param address Destination for the remote SocketAddress or null 00155 * @param buffer The buffer for storing the incoming packet data 00156 * If a packet is too long to fit in the supplied buffer, 00157 * excess bytes are discarded 00158 * @param size The length of the buffer 00159 * @return The number of received bytes on success, negative on failure 00160 * @note This call is not-blocking, if this call would block, must 00161 * immediately return NSAPI_ERROR_WOULD_WAIT 00162 */ 00163 virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); 00164 00165 /** Register a callback on state change of the socket 00166 * @param handle Socket handle 00167 * @param callback Function to call on state change 00168 * @param data Argument to pass to callback 00169 * @note Callback may be called in an interrupt context. 00170 */ 00171 virtual void socket_attach(void *handle, void (*callback)(void *), void *data); 00172 00173 virtual NetworkStack *get_stack() 00174 { 00175 return this; 00176 } 00177 00178 private: 00179 WizFi250 _wizfi250; 00180 bool _ids[WIZFI250_SOCKET_COUNT]; 00181 }; 00182 00183 #endif 00184
Generated on Sat Jul 16 2022 21:04:00 by 1.7.2