test

Fork of WizFi250Interface by WIZnet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WizFi250Interface.h Source File

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