NNN50 WIFI_API library

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

This is mbed compatible EthernetInterface lib exclude for Delta DFCM-NNN50 platform.

Additional information and examples can be found in mbed Handbook

Committer:
tsungta
Date:
Wed Nov 23 17:36:49 2016 +0000
Revision:
0:06fccc63b33d
Child:
12:35ad849d24e3
20:7c3d78d; alpha release for NNN50; SoftAP mode is not yet supported.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsungta 0:06fccc63b33d 1 /* Copyright (C) 2012 mbed.org, MIT License
tsungta 0:06fccc63b33d 2 *
tsungta 0:06fccc63b33d 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tsungta 0:06fccc63b33d 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tsungta 0:06fccc63b33d 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tsungta 0:06fccc63b33d 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tsungta 0:06fccc63b33d 7 * furnished to do so, subject to the following conditions:
tsungta 0:06fccc63b33d 8 *
tsungta 0:06fccc63b33d 9 * The above copyright notice and this permission notice shall be included in all copies or
tsungta 0:06fccc63b33d 10 * substantial portions of the Software.
tsungta 0:06fccc63b33d 11 *
tsungta 0:06fccc63b33d 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tsungta 0:06fccc63b33d 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tsungta 0:06fccc63b33d 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tsungta 0:06fccc63b33d 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tsungta 0:06fccc63b33d 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tsungta 0:06fccc63b33d 17 */
tsungta 0:06fccc63b33d 18 #ifndef SOCKET_H_
tsungta 0:06fccc63b33d 19 #define SOCKET_H_
tsungta 0:06fccc63b33d 20
tsungta 0:06fccc63b33d 21 //Tsungta #include "lwip/sockets.h"
tsungta 0:06fccc63b33d 22 //Tsungta #include "lwip/netdb.h"
tsungta 0:06fccc63b33d 23
tsungta 0:06fccc63b33d 24 // following are added by Tsungta
tsungta 0:06fccc63b33d 25 #define SOCKET_CB_ARRAY_SIZE TCP_SOCK_MAX*2//double up space to prevent unexpected _sock, in some case _sock may > than TCP_SOCK_MAX
tsungta 0:06fccc63b33d 26 #include "mbed.h"
tsungta 0:06fccc63b33d 27 #include "driver/include/m2m_wifi.h"//Tsungta
tsungta 0:06fccc63b33d 28 #include "socket/include/socket.h"//Tsungta
tsungta 0:06fccc63b33d 29 #include <stddef.h>
tsungta 0:06fccc63b33d 30 #include "stdint.h"
tsungta 0:06fccc63b33d 31 #define DELAY_MS_UNIT 30
tsungta 0:06fccc63b33d 32 #define socklen_t uint32_t
tsungta 0:06fccc63b33d 33 struct timeval {
tsungta 0:06fccc63b33d 34 long tv_sec; /* seconds */
tsungta 0:06fccc63b33d 35 long tv_usec; /* and microseconds */
tsungta 0:06fccc63b33d 36 };
tsungta 0:06fccc63b33d 37 //Tsungta
tsungta 0:06fccc63b33d 38
tsungta 0:06fccc63b33d 39 //DNS
tsungta 0:06fccc63b33d 40 inline struct hostent *gethostbyname(const char *name) {
tsungta 0:06fccc63b33d 41 return 0;//Tsungta lwip_gethostbyname(name);
tsungta 0:06fccc63b33d 42 }
tsungta 0:06fccc63b33d 43
tsungta 0:06fccc63b33d 44 //Tsungta
tsungta 0:06fccc63b33d 45 //inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
tsungta 0:06fccc63b33d 46 // return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
tsungta 0:06fccc63b33d 47 //}
tsungta 0:06fccc63b33d 48
tsungta 0:06fccc63b33d 49 class TimeInterval;
tsungta 0:06fccc63b33d 50
tsungta 0:06fccc63b33d 51 /** Socket file descriptor and select wrapper
tsungta 0:06fccc63b33d 52 */
tsungta 0:06fccc63b33d 53 class Socket {
tsungta 0:06fccc63b33d 54 public:
tsungta 0:06fccc63b33d 55 /** Socket
tsungta 0:06fccc63b33d 56 */
tsungta 0:06fccc63b33d 57 Socket();
tsungta 0:06fccc63b33d 58
tsungta 0:06fccc63b33d 59 /** Set blocking or non-blocking mode of the socket and a timeout on
tsungta 0:06fccc63b33d 60 blocking socket operations
tsungta 0:06fccc63b33d 61 \param blocking true for blocking mode, false for non-blocking mode.
tsungta 0:06fccc63b33d 62 \param timeout timeout in ms [Default: (1500)ms].
tsungta 0:06fccc63b33d 63 */
tsungta 0:06fccc63b33d 64 void set_blocking(bool blocking, unsigned int timeout=1500);
tsungta 0:06fccc63b33d 65
tsungta 0:06fccc63b33d 66 /** Set socket options
tsungta 0:06fccc63b33d 67 \param level stack level (see: lwip/sockets.h)
tsungta 0:06fccc63b33d 68 \param optname option ID
tsungta 0:06fccc63b33d 69 \param optval option value
tsungta 0:06fccc63b33d 70 \param socklen_t length of the option value
tsungta 0:06fccc63b33d 71 \return 0 on success, -1 on failure
tsungta 0:06fccc63b33d 72 */
tsungta 0:06fccc63b33d 73 int set_option(int level, int optname, const void *optval, socklen_t optlen);
tsungta 0:06fccc63b33d 74
tsungta 0:06fccc63b33d 75 /** Get socket options
tsungta 0:06fccc63b33d 76 \param level stack level (see: lwip/sockets.h)
tsungta 0:06fccc63b33d 77 \param optname option ID
tsungta 0:06fccc63b33d 78 \param optval buffer pointer where to write the option value
tsungta 0:06fccc63b33d 79 \param socklen_t length of the option value
tsungta 0:06fccc63b33d 80 \return 0 on success, -1 on failure
tsungta 0:06fccc63b33d 81 */
tsungta 0:06fccc63b33d 82 int get_option(int level, int optname, void *optval, socklen_t *optlen);
tsungta 0:06fccc63b33d 83
tsungta 0:06fccc63b33d 84 /** Close the socket
tsungta 0:06fccc63b33d 85 \param shutdown free the left-over data in message queues
tsungta 0:06fccc63b33d 86 */
tsungta 0:06fccc63b33d 87 int close(bool shutdown=true);
tsungta 0:06fccc63b33d 88
tsungta 0:06fccc63b33d 89 ~Socket();
tsungta 0:06fccc63b33d 90
tsungta 0:06fccc63b33d 91 protected:
tsungta 0:06fccc63b33d 92 int _sock_fd;
tsungta 0:06fccc63b33d 93 int init_socket(int type);
tsungta 0:06fccc63b33d 94
tsungta 0:06fccc63b33d 95 int wait_readable(TimeInterval& timeout);
tsungta 0:06fccc63b33d 96 int wait_writable(TimeInterval& timeout);
tsungta 0:06fccc63b33d 97
tsungta 0:06fccc63b33d 98 bool _blocking;
tsungta 0:06fccc63b33d 99 unsigned int _timeout;
tsungta 0:06fccc63b33d 100
tsungta 0:06fccc63b33d 101 private:
tsungta 0:06fccc63b33d 102 int select(struct timeval *timeout, bool read, bool write);
tsungta 0:06fccc63b33d 103 };
tsungta 0:06fccc63b33d 104
tsungta 0:06fccc63b33d 105 /** Time interval class used to specify timeouts
tsungta 0:06fccc63b33d 106 */
tsungta 0:06fccc63b33d 107 class TimeInterval {
tsungta 0:06fccc63b33d 108 friend class Socket;
tsungta 0:06fccc63b33d 109
tsungta 0:06fccc63b33d 110 public:
tsungta 0:06fccc63b33d 111 /** Time Interval
tsungta 0:06fccc63b33d 112 \param ms time interval expressed in milliseconds
tsungta 0:06fccc63b33d 113 */
tsungta 0:06fccc63b33d 114 TimeInterval(unsigned int ms);
tsungta 0:06fccc63b33d 115
tsungta 0:06fccc63b33d 116 private:
tsungta 0:06fccc63b33d 117 struct timeval _time;
tsungta 0:06fccc63b33d 118 };
tsungta 0:06fccc63b33d 119
tsungta 0:06fccc63b33d 120 #endif /* SOCKET_H_ */