28 #include "mx_wifi_conf.h" 38 #define MX_WIFI_API_VERSION_MAJ (2) 39 #define MX_WIFI_API_VERSION_SUB (1) 40 #define MX_WIFI_API_VERSION_REV (10) 46 #define MX_MAX_IP_LEN (16) 47 #define MX_MAX_SSID_LEN (32) 48 #define MX_MAX_KEY_LEN (64) 49 #define MX_MAX_BSSID_LEN (6) 50 #define MX_MAX_DNSNAME_LEN (253) 51 #define MX_MAX_IDENTITY_LEN (32) 52 #define MX_TLS_SNI_SERVERNAME_SIZE (128) 53 #define MX_SERVICE_NAME_SIZE (255) 54 #define MC_WIFI_INTERFACE_NUM (2) 55 #define MX_WIFI_PING_MAX (10) 57 #define MX_WIFI_SCAN_TIMEOUT (5000) 86 char localip[MX_MAX_IP_LEN];
87 char netmask[MX_MAX_IP_LEN];
88 char gateway[MX_MAX_IP_LEN];
89 char dnserver[MX_MAX_IP_LEN];
109 const char *client_cert;
111 const char *client_key;
118 #define MX_WIFI_STATUS_OK (0) 119 #define MX_WIFI_STATUS_ERROR (-1) 120 #define MX_WIFI_STATUS_TIMEOUT (-2) 121 #define MX_WIFI_STATUS_IO_ERROR (-3) 122 #define MX_WIFI_STATUS_PARAM_ERROR (-4) 123 #define MX_WIFI_STATUS_T int32_t 126 #define MX_WIFI_MAC_SIZE (6) 127 #define MX_WIFI_SCAN_BUF_SIZE (2000) 129 #define MIN(a, b) ( ((a) < (b)) ? (a) : (b)) 133 #define IP6_ADDR_INVALID 0x00 134 #define IP6_ADDR_TENTATIVE 0x08 135 #define IP6_ADDR_TENTATIVE_1 0x09 136 #define IP6_ADDR_TENTATIVE_2 0x0a 137 #define IP6_ADDR_TENTATIVE_3 0x0b 138 #define IP6_ADDR_TENTATIVE_4 0x0c 139 #define IP6_ADDR_TENTATIVE_5 0x0d 140 #define IP6_ADDR_TENTATIVE_6 0x0e 141 #define IP6_ADDR_TENTATIVE_7 0x0f 142 #define IP6_ADDR_VALID 0x10 143 #define IP6_ADDR_PREFERRED 0x30 144 #define IP6_ADDR_DEPRECATED 0x50 195 uint8_t Product_Name[MX_WIFI_PRODUCT_NAME_SIZE];
196 uint8_t Product_ID[MX_WIFI_PRODUCT_ID_SIZE];
197 uint8_t FW_Rev[MX_WIFI_FW_REV_SIZE];
207 uint8_t SSID[MX_WIFI_MAX_SSID_NAME_SIZE + 1];
208 uint8_t pswd[MX_WIFI_MAX_PSWD_NAME_SIZE + 1];
216 uint8_t Gateway_Addr[4];
219 int32_t IP6_state[3];
220 uint8_t IP6_Addr[3][16];
221 uint8_t IP6_Mask[16];
222 uint8_t Gateway6_Addr[16];
223 uint8_t IP6_DNS1[16];
231 char SSID[MX_WIFI_MAX_SSID_NAME_SIZE + 1];
232 char pswd[MX_WIFI_MAX_PSWD_NAME_SIZE + 1];
255 MX_WIFI_FOTA_SUCCESS,
277 void *callback_arg[MC_WIFI_INTERFACE_NUM];
310 LOCK_DECLARE(lockcmd);
423 #if (MX_WIFI_NETWORK_BYPASS_MODE == 1) 466 MWIFI_EVENT_NONE = 0x00,
473 typedef uint8_t mwifi_status_t;
488 char ssid[MX_MAX_SSID_LEN];
489 uint8_t bssid[MX_MAX_BSSID_LEN];
580 mwifi_if_t interface);
599 const char *Password, MX_WIFI_SecurityType_t SecType);
612 const char *Identity,
const char *Password,
714 #if MX_WIFI_NETWORK_BYPASS_MODE == 0 723 #define socklen_t uint32_t 764 uint32_t u32_addr[4];
778 uint32_t sin6_flowinfo;
780 uint32_t sin6_scope_id;
788 uint32_t s2_data2[3];
789 uint32_t s2_data3[3];
808 #define SOCK_STREAM 1 812 #define SOL_SOCKET 0xfff 818 #define PF_UNSPEC AF_UNSPEC 819 #define PF_INET AF_INET 820 #define PF_INET6 AF_INET6 823 #define IPPROTO_ICMP 1 824 #define IPPROTO_TCP 6 825 #define IPPROTO_UDP 17 826 #define IPPROTO_IPV6 41 827 #define IPPROTO_ICMPV6 58 828 #define IPPROTO_UDPLITE 136 861 #if !defined __GNUC__ 862 #define FD_SETSIZE 64 863 #define HOWMANY(x, y) (((x) + ((y) - 1)) / (y)) 866 #define NFDBITS (sizeof(unsigned long) * NBBY) 868 #define MC_FDSET_MASK(n) ((unsigned long)1 << ((n) % NFDBITS)) 875 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= MC_FDSET_MASK(n)) 876 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~MC_FDSET_MASK(n)) 877 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & MC_FDSET_MASK(n)) 878 #define FD_ZERO(p) memset((p), 0, sizeof(*(p))) 888 IP_MULTICAST_TTL = 0x0005,
889 IP_MULTICAST_IF = 0x0006,
890 IP_MULTICAST_LOOP = 0x0007
914 int32_t optname,
const void *optvalue, int32_t optlen);
927 int32_t optname,
void *optvalue, uint32_t *optlen);
1022 struct sockaddr *toaddr, int32_t toaddrlen);
1036 struct sockaddr *fromaddr, uint32_t *fromaddrlen);
1057 int32_t response[]);
1069 int32_t MX_WIFI_Socket_getaddrinfo(
MX_WIFIObject_t *Obj,
const char *nodename,
const char *servname,
1070 const struct addrinfo *hints,
struct mc_addrinfo *res);
1094 fd_set *exceptfds,
struct mc_timeval *timeout);
1133 #define MDNS_MAX_LABEL_LEN 63 1140 #define MDNS_MAX_NAME_LEN 255 1147 #define MDNS_MAX_KEYVAL_LEN 255 1151 #define MDNS_PROTO_TCP 0 1153 #define MDNS_PROTO_UDP 1 1156 #define MAX_MDNS_LST 5 1159 #define ERR_MDNS_BASE -36650 1160 #define ERR_MDNS_INVAL -36651 1161 #define ERR_MDNS_BADSRC -36652 1162 #define ERR_MDNS_TOOBIG -36653 1163 #define ERR_MDNS_NOIMPL -36654 1164 #define ERR_MDNS_NOMEM -36655 1165 #define ERR_MDNS_INUSE -36656 1166 #define ERR_MDNS_NORESP -36657 1167 #define ERR_MDNS_FSOC -36658 1168 #define ERR_MDNS_FREUSE -36659 1169 #define ERR_MDNS_FBINDTODEVICE -36660 1170 #define ERR_MDNS_FBIND -36661 1171 #define ERR_MDNS_FMCAST_JOIN -36662 1172 #define ERR_MDNS_FMCAST_SET -36663 1173 #define ERR_MDNS_FQUERY_SOC -36664 1174 #define ERR_MDNS_FQUERY_THREAD -36665 1175 #define ERR_MDNS_END -36670 1225 uint32_t ip6addr[4];
1329 typedef uint8_t mtls_ver_t;
1375 const struct sockaddr *addr, int32_t addrlen,
char *ca, int32_t calen);
1392 const struct sockaddr *addr, int32_t addrlen,
char *ca, int32_t calen);
int32_t MX_WIFI_MDNS_set_hostname(MX_WIFIObject_t *Obj, char *hostname)
Set new host name, use mdns_iface_state_change(interface, REANNOUNCE) to anounce the new host name...
int32_t MX_WIFI_ResetModule(MX_WIFIObject_t *Obj)
Reset the module by Software.
DOWN the interface and de-announce services mDNS sends good bye packet with ttl=0 so that mDNS client...
int32_t MX_WIFI_TLS_set_clientCertificate(MX_WIFIObject_t *Obj, uint8_t *client_cert, uint16_t cert_len)
TLS set client certificate.
int32_t MX_WIFI_Socket_accept(MX_WIFIObject_t *Obj, int32_t sockfd, struct sockaddr *addr, uint32_t *addrlen)
Accept a socket.
uint16_t port
Port number.
uint8_t interfaces
Num of Wi-Fi interfaces inited, 2 if STA+AP inited.
IO_Receive_Func IO_Receive
I/O interface receive function.
int32_t MX_WIFI_MDNS_deannounce_service(MX_WIFIObject_t *Obj, struct mc_mdns_service *service, mwifi_if_t interface)
deannounce a service.
int32_t MX_WIFI_Webserver_stop(MX_WIFIObject_t *Obj)
Stop webserver.
Recv timeout in block mode.
uint8_t mwifi_security_t
Wi-Fi softAP info.
int8_t MX_WIFI_Get_scan_result(MX_WIFIObject_t *Obj, uint8_t *results, uint8_t number)
wifi get scan result
int32_t MX_WIFI_SetTimeout(MX_WIFIObject_t *Obj, uint32_t Timeout)
Change default Timeout for wifi cmd.
int32_t MX_WIFI_GetIP6Address(MX_WIFIObject_t *Obj, uint8_t *ipaddr6, int32_t addr_num, mwifi_if_t wifi_if)
Get the local IPv6 address of the wifi module.
IO_Init_Func IO_Init
I/O interface init function.
void * netlink_user_args
netlink input callback argument.
uint8_t security
Wi-Fi connection security type.
int32_t MX_WIFI_TLS_set_clientPrivateKey(MX_WIFIObject_t *Obj, uint8_t *client_private_key, uint16_t key_len)
TLS set client private key.
uint8_t mc_wifi_scan_mode_t
wifi scan mode.
int32_t MX_WIFI_TLS_close(MX_WIFIObject_t *Obj, mtls_t tls)
Close the TLS session, release resource.
int32_t MX_WIFI_Socket_create(MX_WIFIObject_t *Obj, int32_t domain, int32_t type, int32_t protocol)
Create a socket.
int32_t MX_WIFI_TLS_connect_sni(MX_WIFIObject_t *Obj, const char *sni_servername, int32_t sni_servername_len, const struct sockaddr *addr, int32_t addrlen, char *ca, int32_t calen)
TLS client create a TLS connection with SNI.
uint8_t is_connected
Wi-Fi station connection status.
Wired Equivalent Privacy.
Wi-Fi module reset(reboot).
IO_Delay_Func IO_Delay
I/O interface delay function.
int32_t MX_WIFI_RegisterStatusCallback_if(MX_WIFIObject_t *Obj, mx_wifi_status_callback_t cb, void *arg, mwifi_if_t interface)
< status code.
int32_t MX_WIFI_DeInit(MX_WIFIObject_t *Obj)
DeInitialize WIFI module.
int32_t MX_WIFI_GetMACAddress(MX_WIFIObject_t *Obj, uint8_t *mac)
Get the MAC address of the wifi module.
int32_t MX_WIFI_MDNS_start(MX_WIFIObject_t *Obj, const char *domain, char *hostname)
start mDNS service.
void(* mx_wifi_netlink_input_cb_t)(mx_buf_t *pbuf, void *user_args)
Prototype of netlink input callback function for network bypass mode.
MX_WIFI_SecurityType_t
Security settings for wifi network.
int32_t MX_WIFI_Socket_recv(MX_WIFIObject_t *Obj, int32_t sockfd, uint8_t *buf, int32_t len, int32_t flags)
Socket recv.
int32_t MX_WIFI_TLS_set_nonblock(MX_WIFIObject_t *Obj, mtls_t tls, int32_t nonblock)
Set TLS nonblock mode.
iface_state
mDNS Interface State mDNS interface state can be changed by using mdns_iface_state_change() function...
void md5(unsigned char *input, int ilen, unsigned char output[16])
Output = MD5( input buffer )
int32_t MX_WIFI_StopAP(MX_WIFIObject_t *Obj)
Stop softAP(miniAP) mode.
Unimplemented: turn on debugging info recording.
int32_t MX_WIFI_Socket_shutdown(MX_WIFIObject_t *Obj, int32_t sockfd, int32_t mode)
Socket shutdown.
Send timeout in block mode.
#define MDNS_MAX_KEYVAL_LEN
Maximum length of key/value pair.
UP the interface and announce services mDNS will probe and announce all services announced via mdns_a...
void * mtls_t
mxchip TLS handler type
int32_t MX_WIFI_Socket_sendto(MX_WIFIObject_t *Obj, int32_t sockfd, uint8_t *buf, int32_t len, int32_t flags, struct sockaddr *toaddr, int32_t toaddrlen)
Socket sendto.
Bypass hardware when possible.
Wi-Fi low level I/O interface operation handles.
int32_t MX_WIFI_HardResetModule(MX_WIFIObject_t *Obj)
Reset wifi module by hardware IO.
uint8_t channel
Wi-Fi softAP Channel.
int32_t MX_WIFI_Socket_getsockopt(MX_WIFIObject_t *Obj, int32_t sockfd, int32_t level, int32_t optname, void *optvalue, uint32_t *optlen)
Get option of a socket.
MX_WIFI_SecurityType_t Security
Wi-Fi station security.
int32_t MX_WIFI_UnRegisterStatusCallback(MX_WIFIObject_t *Obj)
UnRegister wifi status changed callback.
int32_t MX_WIFI_Init(MX_WIFIObject_t *Obj)
Initialize WIFI module and get module fw & mac info.
mwifi_security_t security
security of the AP
linger on close if data present
int32_t MX_WIFI_Socket_setsockopt(MX_WIFIObject_t *Obj, int32_t sockfd, int32_t level, int32_t optname, const void *optvalue, int32_t optlen)
Set option for a socket.
int32_t MX_WIFI_Socket_send(MX_WIFIObject_t *Obj, int32_t sockfd, uint8_t *buf, int32_t len, int32_t flags)
Socket send.
uint32_t fota_user_args
FOTA status callback argument.
int32_t MX_WIFI_Disconnect(MX_WIFIObject_t *Obj)
Disconnect from a network.
MX_WIFI_IO_t fops
Wi-Fi low level I/O operation handles.
int8_t(* IO_Init_Func)(uint16_t mode)
I/O interface init function.
SOCK_OPT_VAL
socket option value
IO_Send_Func IO_Send
I/O interface send function.
void(* mx_wifi_status_callback_t)(uint8_t cate, uint8_t event, void *arg)
Prototype of Wi-Fi status changed callback function.
uint16_t(* IO_Send_Func)(uint8_t *data, uint16_t len)
I/O interface send function.
mx_wifi_netlink_input_cb_t netlink_input_cb
netlink input callback.
uint8_t mwifi_if_t
wifi mode.
IP_OPT_VAL
IP option types, level: IPPROTO_IP.
Wi-Fi station got ip event.
Just use interface addresses.
int32_t MX_WIFI_TLS_recv(MX_WIFIObject_t *Obj, mtls_t tls, void *buf, int32_t len)
TLS redeive data.
int32_t MX_WIFI_Socket_ping(MX_WIFIObject_t *Obj, const char *hostname, int32_t count, int32_t delay, int32_t response[])
Ping a host, only for IPv4 address.
IO_DeInit_Func IO_DeInit
I/O interface deinit function.
MX_WIFI_Network_t NetSettings
Wi-Fi station info.
int32_t MX_WIFI_MDNS_iface_state_change(MX_WIFIObject_t *Obj, mwifi_if_t interface, enum iface_state state)
Send interface state change event to mdns.
int32_t MX_WIFI_Socket_close(MX_WIFIObject_t *Obj, int32_t sockfd)
Socket close.
int32_t MX_WIFI_WPS_Connect(MX_WIFIObject_t *Obj)
Join an Access point with WPS (PUSH-BUTTON) mode.
set socket as block(optval=0)/non-block(optval=1) mode.
Forcefully re-announce services This state should be used after services are already announced and fo...
Allow local address & port reuse.
socket address(IPV6 net format)
int32_t MX_WIFI_IO_YIELD(MX_WIFIObject_t *Obj, uint32_t timeout)
Yield data from Wi-Fi module.
int8_t(* IO_DeInit_Func)(void)
I/O interface deinit function.
uint32_t ipaddr
IP Address of device.
int32_t MX_WIFI_TLS_send(MX_WIFIObject_t *Obj, mtls_t tls, void *data, int32_t len)
TLS send data.
Main packet buffer struct.
MX_WIFI_InitMode_t
Wi-Fi module init type.
int32_t MX_WIFI_MDNS_set_txt_rec(MX_WIFIObject_t *Obj, struct mc_mdns_service *service, char *keyvals, char separator)
sets the TXT record field for a given mDNS service.
socket address(net format)
Permit to send and to receive broadcast messages.
int32_t MX_WIFI_Scan(MX_WIFIObject_t *Obj, mc_wifi_scan_mode_t scan_mode, char *ssid, int32_t len)
wifi block scan
uint8_t DHCP_IsEnabled
Wi-Fi station DHCP.
int32_t MX_WIFI_MDNS_stop(MX_WIFIObject_t *Obj)
stop mDNS service.
int32_t MX_WIFI_Socket_getsockname(MX_WIFIObject_t *Obj, int32_t sockfd, struct sockaddr *addr, uint32_t *addrlen)
socket getsockname.
int32_t MX_WIFI_GetVersion(MX_WIFIObject_t *Obj, uint8_t *version, uint32_t size)
Get the firmware version string of the wifi module.
int32_t MX_WIFI_StartAP(MX_WIFIObject_t *Obj, MX_WIFI_APSettings_t *ap_settings)
Start softAP(miniAP) mode.
int32_t MX_WIFI_Socket_listen(MX_WIFIObject_t *Obj, int32_t sockfd, int32_t backlog)
Listen a socket.
int32_t MX_WIFI_Socket_recvfrom(MX_WIFIObject_t *Obj, int32_t sockfd, uint8_t *buf, int32_t len, int32_t flags, struct sockaddr *fromaddr, uint32_t *fromaddrlen)
Socket recvfrom.
int32_t MX_WIFI_Socket_gethostbyname(MX_WIFIObject_t *Obj, struct sockaddr *addr, char *name)
Gethostbyname, only for IPv4 address.
int32_t MX_WIFI_WPS_Stop(MX_WIFIObject_t *Obj)
Stop WPS connect.
mx_wifi_fota_status_e
FOTA status.
It is used when calling mwifi_connect, MXOS read security type from scan result.
MX_WIFI_SystemInfo_t SysInfo
Wi-Fi system info.
int32_t MX_WIFI_Connect(MX_WIFIObject_t *Obj, const char *SSID, const char *Password, MX_WIFI_SecurityType_t SecType)
Join an Access point.
int32_t MX_WIFI_station_powersave(MX_WIFIObject_t *Obj, int32_t ps_onoff)
set powersave onoff for wifi station mode.
int32_t MX_WIFI_Socket_bind(MX_WIFIObject_t *Obj, int32_t sockfd, const struct sockaddr *addr, int32_t addrlen)
Bind a socket.
int32_t MX_WIFI_Socket_getpeername(MX_WIFIObject_t *Obj, int32_t sockfd, struct sockaddr *addr, uint32_t *addrlen)
socket getpeername.
#define NFDBITS
bits per mask
mwifi_ip_attr_t ip
Wi-Fi softAP IP settings.
int32_t MX_WIFI_GetIPAddress(MX_WIFIObject_t *Obj, uint8_t *ipaddr, mwifi_if_t wifi_if)
Get the local IPv4 address of the wifi module.
int32_t MX_WIFI_TLS_set_ver(MX_WIFIObject_t *Obj, mtls_ver_t version)
set the TLS protocol version.
int32_t MX_WIFI_MDNS_announce_service(MX_WIFIObject_t *Obj, struct mc_mdns_service *service, mwifi_if_t interface)
announce a service.
Wi-Fi module init(not reboot).
int32_t MX_WIFI_RegisterStatusCallback(MX_WIFIObject_t *Obj, mx_wifi_status_callback_t cb, void *arg)
Register wifi status changed callback.
void(* mx_wifi_fota_status_cb_t)(mx_wifi_fota_status_e status, uint32_t user_args)
Prototype of FOTA status callback function.
uint8_t scan_number
Num of Wi-Fi scan result to get.
int32_t channel
Channel of the AP.
#define MDNS_MAX_LABEL_LEN
Maximum length of labels.
#define MX_WIFI_SCAN_BUF_SIZE
max size of scan buffer.
Allow local address reuse.
int32_t MX_WIFI_UnRegisterStatusCallback_if(MX_WIFIObject_t *Obj, mwifi_if_t interface)
< status code.
#define MX_WIFI_STATUS_T
status code.
Wi-Fi Wi-Fi object handle.
uint16_t(* IO_Receive_Func)(uint8_t *buffer, uint16_t buff_size)
I/O interface receive function.
int32_t MX_WIFI_TLS_connect(MX_WIFIObject_t *Obj, int32_t domain, int32_t type, int32_t protocol, const struct sockaddr *addr, int32_t addrlen, char *ca, int32_t calen)
TLS client create a TLS connection.
int32_t MX_WIFI_Socket_connect(MX_WIFIObject_t *Obj, int32_t sockfd, const struct sockaddr *addr, int32_t addrlen)
Socket connect.
socket address_in6 struct
int8_t IsConnected
Wi-Fi station connection status.
int32_t MX_WIFI_FOTA_start(MX_WIFIObject_t *Obj, const char *url, const char *md5, mx_wifi_fota_status_cb_t fota_status_callback, uint32_t user_args)
Start FOTA.
int32_t rssi
Signal strength of the AP.
int32_t MX_WIFI_RegisterBusIO(MX_WIFIObject_t *Obj, IO_Init_Func IO_Init, IO_DeInit_Func IO_DeInit, IO_Delay_Func IO_Delay, IO_Send_Func IO_Send, IO_Receive_Func IO_Receive)
Register low level IO interface.
mx_wifi_fota_status_cb_t fota_status_cb
FOTA status callback.
int32_t MX_WIFI_Webserver_start(MX_WIFIObject_t *Obj)
Start webserver.
Wi-Fi station down event.
uint32_t Timeout
Wi-Fi cmd timeout in ms.
#define FD_SETSIZE
MAX fd number is 64 in MXOS.
#define MX_WIFI_MAC_SIZE
max length of MAC address.
int32_t proto
Protocol used.
MX_WIFI_APSettings_t APSettings
Wi-Fi softAP info.
int32_t rssi
Wi-Fi connection rssi.
int32_t MX_WIFI_EAP_Connect(MX_WIFIObject_t *Obj, const char *SSID, const char *Identity, const char *Password, mwifi_eap_attr_t *attr, mwifi_ip_attr_t *ip)
Join an Access point with WPA-E.
Don't create UDP checksum.
int8_t MX_WIFI_IsConnected(MX_WIFIObject_t *Obj)
Check whether the module is connected to an access point.
void(* IO_Delay_Func)(uint32_t ms)
I/O interface delay function.
MX_WIFI_Runtime_t Runtime
Wi-Fi runtime info.
Leave received OOB data in line.
int32_t MX_WIFI_GetIP6AddressState(MX_WIFIObject_t *Obj, int32_t addr_num, mwifi_if_t wifi_if)
Get the local IPv6 address state of the wifi module.
int32_t MX_WIFI_MDNS_deannounce_service_all(MX_WIFIObject_t *Obj, mwifi_if_t interface)
deannounce all services.
char separator
separator for txt record
int32_t MX_WIFI_ResetToFactoryDefault(MX_WIFIObject_t *Obj)
Reset To factory defaults.
uint8_t channel
Wi-Fi connection channel.