Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
wifi_winc1500.c File Reference
#include <logging/log.h>
#include <zephyr.h>
#include <kernel.h>
#include <debug/stack.h>
#include <device.h>
#include <string.h>
#include <errno.h>
#include <net/net_pkt.h>
#include <net/net_if.h>
#include <net/net_l2.h>
#include <net/net_context.h>
#include <net/net_offload.h>
#include <net/wifi_mgmt.h>
#include <sys/printk.h>
#include <driver/include/m2m_wifi.h>
#include <socket/include/m2m_socket_host_if.h>

Data Structures

struct  tstrSocketBindMsg
 
struct  tstrSocketListenMsg
 
struct  tstrSocketAcceptMsg
 
struct  tstrSocketConnectMsg
 
struct  tstrSocketRecvMsg
 
struct  socket_data
 
struct  winc1500_data
 

Macros

#define LOG_MODULE_NAME   wifi_winc1500
 
#define LOG_LEVEL   CONFIG_WIFI_LOG_LEVEL
 
#define HOSTNAME_MAX_SIZE   (64)
 
#define WINC1500_BIND_TIMEOUT   K_MSEC(500)
 
#define WINC1500_LISTEN_TIMEOUT   K_MSEC(500)
 
#define WINC1500_BUF_TIMEOUT   K_MSEC(100)
 

Typedefs

typedef void(* tpfAppSocketCb) (SOCKET sock, uint8 u8Msg, void *pvMsg)
 
typedef void(* tpfAppResolveCb) (uint8 *pu8DomainName, uint32 u32ServerIP)
 

Enumerations

enum  socket_errors {
  SOCK_ERR_NO_ERROR = 0 , SOCK_ERR_INVALID_ADDRESS = -1 , SOCK_ERR_ADDR_ALREADY_IN_USE = -2 , SOCK_ERR_MAX_TCP_SOCK = -3 ,
  SOCK_ERR_MAX_UDP_SOCK = -4 , SOCK_ERR_INVALID_ARG = -6 , SOCK_ERR_MAX_LISTEN_SOCK = -7 , SOCK_ERR_INVALID = -9 ,
  SOCK_ERR_ADDR_IS_REQUIRED = -11 , SOCK_ERR_CONN_ABORTED = -12 , SOCK_ERR_TIMEOUT = -13 , SOCK_ERR_BUFFER_FULL = -14
}
 
enum  socket_messages {
  SOCKET_MSG_BIND = 1 , SOCKET_MSG_LISTEN , SOCKET_MSG_DNS_RESOLVE , SOCKET_MSG_ACCEPT ,
  SOCKET_MSG_CONNECT , SOCKET_MSG_RECV , SOCKET_MSG_SEND , SOCKET_MSG_SENDTO ,
  SOCKET_MSG_RECVFROM
}
 

Functions

 LOG_MODULE_REGISTER (wifi_winc1500)
 
NMI_API void socketInit (void)
 
NMI_API void registerSocketCallback (tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb)
 
NMI_API SOCKET socket (uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
 
NMI_API sint8 bind (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
NMI_API sint8 listen (SOCKET sock, uint8 backlog)
 
NMI_API sint8 accept (SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
 
NMI_API sint8 connect (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
NMI_API sint16 recv (SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
 
NMI_API sint16 send (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)
 
NMI_API sint16 sendto (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
 
NMI_API sint8 close (SOCKET sock)
 
 NET_BUF_POOL_DEFINE (winc1500_tx_pool, CONFIG_WIFI_WINC1500_BUF_CTR, CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE, 0, NULL)
 
 NET_BUF_POOL_DEFINE (winc1500_rx_pool, CONFIG_WIFI_WINC1500_BUF_CTR, CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE, 0, NULL)
 
 K_KERNEL_STACK_MEMBER (winc1500_stack, CONFIG_WIFI_WINC1500_THREAD_STACK_SIZE)
 
static int winc1500_get (sa_family_t family, enum net_sock_type type, enum net_ip_protocol ip_proto, struct net_context **context)
 
static int winc1500_bind (struct net_context *context, const struct sockaddr *addr, socklen_t addrlen)
 
static int winc1500_listen (struct net_context *context, int backlog)
 
static int winc1500_connect (struct net_context *context, const struct sockaddr *addr, socklen_t addrlen, net_context_connect_cb_t cb, int32_t timeout, void *user_data)
 
static int winc1500_accept (struct net_context *context, net_tcp_accept_cb_t cb, int32_t timeout, void *user_data)
 
static int winc1500_send (struct net_pkt *pkt, net_context_send_cb_t cb, int32_t timeout, void *user_data)
 
static int winc1500_sendto (struct net_pkt *pkt, const struct sockaddr *dst_addr, socklen_t addrlen, net_context_send_cb_t cb, int32_t timeout, void *user_data)
 
static int prepare_pkt (struct socket_data *sock_data)
 
static int winc1500_recv (struct net_context *context, net_context_recv_cb_t cb, int32_t timeout, void *user_data)
 
static int winc1500_put (struct net_context *context)
 
static void handle_wifi_con_state_changed (void *pvMsg)
 
static void handle_wifi_dhcp_conf (void *pvMsg)
 
static void reset_scan_data (void)
 
static void handle_scan_result (void *pvMsg)
 
static void handle_scan_done (void *pvMsg)
 
static void winc1500_wifi_cb (uint8_t message_type, void *pvMsg)
 
static void handle_socket_msg_connect (struct socket_data *sd, void *pvMsg)
 
static bool handle_socket_msg_recv (SOCKET sock, struct socket_data *sd, void *pvMsg)
 
static void handle_socket_msg_bind (struct socket_data *sd, void *pvMsg)
 
static void handle_socket_msg_listen (struct socket_data *sd, void *pvMsg)
 
static void handle_socket_msg_accept (struct socket_data *sd, void *pvMsg)
 
static void winc1500_socket_cb (SOCKET sock, uint8 message, void *pvMsg)
 
static void winc1500_thread (void)
 
static int winc1500_mgmt_scan (const struct device *dev, scan_result_cb_t cb)
 
static int winc1500_mgmt_connect (const struct device *dev, struct wifi_connect_req_params *params)
 
static int winc1500_mgmt_disconnect (const struct device *dev)
 
static int winc1500_mgmt_ap_enable (const struct device *dev, struct wifi_connect_req_params *params)
 
static int winc1500_mgmt_ap_disable (const struct device *dev)
 
static void winc1500_iface_init (struct net_if *iface)
 
static int winc1500_init (const struct device *dev)
 
 NET_DEVICE_OFFLOAD_INIT (winc1500, CONFIG_WIFI_WINC1500_NAME, winc1500_init, NULL, &w1500_data, NULL, CONFIG_WIFI_INIT_PRIORITY, &winc1500_api, CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE)
 

Variables

struct k_thread winc1500_thread_data
 
static struct winc1500_data w1500_data
 
static struct net_offload winc1500_offload
 
static const struct net_wifi_mgmt_offload winc1500_api
 

Macro Definition Documentation

◆ HOSTNAME_MAX_SIZE

#define HOSTNAME_MAX_SIZE   (64)

◆ LOG_LEVEL

#define LOG_LEVEL   CONFIG_WIFI_LOG_LEVEL

◆ LOG_MODULE_NAME

#define LOG_MODULE_NAME   wifi_winc1500

Copyright (c) 2017 IpTronix

SPDX-License-Identifier: Apache-2.0

◆ WINC1500_BIND_TIMEOUT

#define WINC1500_BIND_TIMEOUT   K_MSEC(500)

◆ WINC1500_BUF_TIMEOUT

#define WINC1500_BUF_TIMEOUT   K_MSEC(100)

◆ WINC1500_LISTEN_TIMEOUT

#define WINC1500_LISTEN_TIMEOUT   K_MSEC(500)

Typedef Documentation

◆ tpfAppResolveCb

typedef void(* tpfAppResolveCb) (uint8 *pu8DomainName, uint32 u32ServerIP)

◆ tpfAppSocketCb

typedef void(* tpfAppSocketCb) (SOCKET sock, uint8 u8Msg, void *pvMsg)

Enumeration Type Documentation

◆ socket_errors

Enumerator
SOCK_ERR_NO_ERROR 
SOCK_ERR_INVALID_ADDRESS 
SOCK_ERR_ADDR_ALREADY_IN_USE 
SOCK_ERR_MAX_TCP_SOCK 
SOCK_ERR_MAX_UDP_SOCK 
SOCK_ERR_INVALID_ARG 
SOCK_ERR_MAX_LISTEN_SOCK 
SOCK_ERR_INVALID 
SOCK_ERR_ADDR_IS_REQUIRED 
SOCK_ERR_CONN_ABORTED 
SOCK_ERR_TIMEOUT 
SOCK_ERR_BUFFER_FULL 

◆ socket_messages

Enumerator
SOCKET_MSG_BIND 
SOCKET_MSG_LISTEN 
SOCKET_MSG_DNS_RESOLVE 
SOCKET_MSG_ACCEPT 
SOCKET_MSG_CONNECT 
SOCKET_MSG_RECV 
SOCKET_MSG_SEND 
SOCKET_MSG_SENDTO 
SOCKET_MSG_RECVFROM 

Function Documentation

◆ accept()

NMI_API sint8 accept ( SOCKET  sock,
struct sockaddr addr,
uint8 *  addrlen 
)

◆ bind()

NMI_API sint8 bind ( SOCKET  sock,
struct sockaddr pstrAddr,
uint8  u8AddrLen 
)

◆ close()

NMI_API sint8 close ( SOCKET  sock)

◆ connect()

NMI_API sint8 connect ( SOCKET  sock,
struct sockaddr pstrAddr,
uint8  u8AddrLen 
)

◆ handle_scan_done()

static void handle_scan_done ( void pvMsg)
static

◆ handle_scan_result()

static void handle_scan_result ( void pvMsg)
static

◆ handle_socket_msg_accept()

static void handle_socket_msg_accept ( struct socket_data sd,
void pvMsg 
)
static

The iface is reset when getting a new context.

Setup remote

◆ handle_socket_msg_bind()

static void handle_socket_msg_bind ( struct socket_data sd,
void pvMsg 
)
static

◆ handle_socket_msg_connect()

static void handle_socket_msg_connect ( struct socket_data sd,
void pvMsg 
)
static

◆ handle_socket_msg_listen()

static void handle_socket_msg_listen ( struct socket_data sd,
void pvMsg 
)
static

◆ handle_socket_msg_recv()

static bool handle_socket_msg_recv ( SOCKET  sock,
struct socket_data sd,
void pvMsg 
)
static

◆ handle_wifi_con_state_changed()

static void handle_wifi_con_state_changed ( void pvMsg)
static

◆ handle_wifi_dhcp_conf()

static void handle_wifi_dhcp_conf ( void pvMsg)
static

◆ K_KERNEL_STACK_MEMBER()

K_KERNEL_STACK_MEMBER ( winc1500_stack  ,
CONFIG_WIFI_WINC1500_THREAD_STACK_SIZE   
)

◆ listen()

NMI_API sint8 listen ( SOCKET  sock,
uint8  backlog 
)

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( wifi_winc1500  )

◆ NET_BUF_POOL_DEFINE() [1/2]

NET_BUF_POOL_DEFINE ( winc1500_rx_pool  ,
CONFIG_WIFI_WINC1500_BUF_CTR  ,
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE  ,
,
NULL   
)

◆ NET_BUF_POOL_DEFINE() [2/2]

NET_BUF_POOL_DEFINE ( winc1500_tx_pool  ,
CONFIG_WIFI_WINC1500_BUF_CTR  ,
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE  ,
,
NULL   
)

◆ NET_DEVICE_OFFLOAD_INIT()

NET_DEVICE_OFFLOAD_INIT ( winc1500  ,
CONFIG_WIFI_WINC1500_NAME  ,
winc1500_init  ,
NULL  ,
w1500_data,
NULL  ,
CONFIG_WIFI_INIT_PRIORITY  ,
winc1500_api,
CONFIG_WIFI_WINC1500_MAX_PACKET_SIZE   
)

◆ prepare_pkt()

static int prepare_pkt ( struct socket_data sock_data)
static

◆ recv()

NMI_API sint16 recv ( SOCKET  sock,
void pvRecvBuf,
uint16  u16BufLen,
uint32  u32Timeoutmsec 
)

◆ registerSocketCallback()

NMI_API void registerSocketCallback ( tpfAppSocketCb  socket_cb,
tpfAppResolveCb  resolve_cb 
)

◆ reset_scan_data()

static void reset_scan_data ( void  )
static

◆ send()

NMI_API sint16 send ( SOCKET  sock,
void pvSendBuffer,
uint16  u16SendLength,
uint16  u16Flags 
)

◆ sendto()

NMI_API sint16 sendto ( SOCKET  sock,
void pvSendBuffer,
uint16  u16SendLength,
uint16  flags,
struct sockaddr pstrDestAddr,
uint8  u8AddrLen 
)

◆ socket()

NMI_API SOCKET socket ( uint16  u16Domain,
uint8  u8Type,
uint8  u8Flags 
)

◆ socketInit()

NMI_API void socketInit ( void  )

◆ winc1500_accept()

static int winc1500_accept ( struct net_context context,
net_tcp_accept_cb_t  cb,
int32_t  timeout,
void user_data 
)
static

This function is called when user wants to accept a connection being established.

◆ winc1500_bind()

static int winc1500_bind ( struct net_context context,
const struct sockaddr addr,
socklen_t  addrlen 
)
static

This function is called when user wants to bind to local IP address.

◆ winc1500_connect()

static int winc1500_connect ( struct net_context context,
const struct sockaddr addr,
socklen_t  addrlen,
net_context_connect_cb_t  cb,
int32_t  timeout,
void user_data 
)
static

This function is called when user wants to create a connection to a peer host.

◆ winc1500_get()

static int winc1500_get ( sa_family_t  family,
enum net_sock_type  type,
enum net_ip_protocol  ip_proto,
struct net_context **  context 
)
static

This function is called when the socket is to be opened.

◆ winc1500_iface_init()

static void winc1500_iface_init ( struct net_if iface)
static

◆ winc1500_init()

static int winc1500_init ( const struct device dev)
static

◆ winc1500_listen()

static int winc1500_listen ( struct net_context context,
int  backlog 
)
static

This function is called when user wants to mark the socket to be a listening one.

◆ winc1500_mgmt_ap_disable()

static int winc1500_mgmt_ap_disable ( const struct device dev)
static

◆ winc1500_mgmt_ap_enable()

static int winc1500_mgmt_ap_enable ( const struct device dev,
struct wifi_connect_req_params params 
)
static

security is hardcoded as open for now

DHCP: 192.168.1.1

◆ winc1500_mgmt_connect()

static int winc1500_mgmt_connect ( const struct device dev,
struct wifi_connect_req_params params 
)
static

◆ winc1500_mgmt_disconnect()

static int winc1500_mgmt_disconnect ( const struct device dev)
static

◆ winc1500_mgmt_scan()

static int winc1500_mgmt_scan ( const struct device dev,
scan_result_cb_t  cb 
)
static

◆ winc1500_put()

static int winc1500_put ( struct net_context context)
static

This function is called when user wants to close the socket.

◆ winc1500_recv()

static int winc1500_recv ( struct net_context context,
net_context_recv_cb_t  cb,
int32_t  timeout,
void user_data 
)
static

This function is called when user wants to receive data from peer host.

◆ winc1500_send()

static int winc1500_send ( struct net_pkt pkt,
net_context_send_cb_t  cb,
int32_t  timeout,
void user_data 
)
static

This function is called when user wants to send data to peer host.

◆ winc1500_sendto()

static int winc1500_sendto ( struct net_pkt pkt,
const struct sockaddr dst_addr,
socklen_t  addrlen,
net_context_send_cb_t  cb,
int32_t  timeout,
void user_data 
)
static

This function is called when user wants to send data to peer host.

◆ winc1500_socket_cb()

static void winc1500_socket_cb ( SOCKET  sock,
uint8  message,
void pvMsg 
)
static

◆ winc1500_thread()

static void winc1500_thread ( void  )
static

◆ winc1500_wifi_cb()

static void winc1500_wifi_cb ( uint8_t  message_type,
void pvMsg 
)
static

Variable Documentation

◆ w1500_data

struct winc1500_data w1500_data
static

◆ winc1500_api

const struct net_wifi_mgmt_offload winc1500_api
static
Initial value:
= {
.iface_api.init = winc1500_iface_init,
.disconnect = winc1500_mgmt_disconnect,
.ap_disable = winc1500_mgmt_ap_disable,
}
static void winc1500_iface_init(struct net_if *iface)
Definition: wifi_winc1500.c:1088
static int winc1500_mgmt_disconnect(const struct device *dev)
Definition: wifi_winc1500.c:1043
static int winc1500_mgmt_ap_disable(const struct device *dev)
Definition: wifi_winc1500.c:1079
static int winc1500_mgmt_scan(const struct device *dev, scan_result_cb_t cb)
Definition: wifi_winc1500.c:980
static int winc1500_mgmt_ap_enable(const struct device *dev, struct wifi_connect_req_params *params)
Definition: wifi_winc1500.c:1056
static int winc1500_mgmt_connect(const struct device *dev, struct wifi_connect_req_params *params)
Definition: wifi_winc1500.c:997

◆ winc1500_offload

struct net_offload winc1500_offload
static
Initial value:
= {
.get = winc1500_get,
.bind = winc1500_bind,
.listen = winc1500_listen,
.connect = winc1500_connect,
.accept = winc1500_accept,
.send = winc1500_send,
.sendto = winc1500_sendto,
.recv = winc1500_recv,
.put = winc1500_put,
}
static int winc1500_send(struct net_pkt *pkt, net_context_send_cb_t cb, int32_t timeout, void *user_data)
Definition: wifi_winc1500.c:451
static int winc1500_listen(struct net_context *context, int backlog)
Definition: wifi_winc1500.c:363
static int winc1500_accept(struct net_context *context, net_tcp_accept_cb_t cb, int32_t timeout, void *user_data)
Definition: wifi_winc1500.c:420
static int winc1500_connect(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen, net_context_connect_cb_t cb, int32_t timeout, void *user_data)
Definition: wifi_winc1500.c:387
static int winc1500_sendto(struct net_pkt *pkt, const struct sockaddr *dst_addr, socklen_t addrlen, net_context_send_cb_t cb, int32_t timeout, void *user_data)
Definition: wifi_winc1500.c:489
static int winc1500_get(sa_family_t family, enum net_sock_type type, enum net_ip_protocol ip_proto, struct net_context **context)
Definition: wifi_winc1500.c:294
static int winc1500_recv(struct net_context *context, net_context_recv_cb_t cb, int32_t timeout, void *user_data)
Definition: wifi_winc1500.c:556
static int winc1500_bind(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen)
Definition: wifi_winc1500.c:330
static int winc1500_put(struct net_context *context)
Definition: wifi_winc1500.c:591

◆ winc1500_thread_data

struct k_thread winc1500_thread_data