4101|0

695

帖子

0

TA的资源

一粒金砂(高级)

楼主
 

MX1081 + 庆科Wifi库函数手册 [复制链接]

AD0005_mxchipWNet_Library.pdf (1.47 MB, 下载次数: 35)

概览通过阅读头文件:

  1. #ifndef __FILE_H__
  2. #define __FILE_H__
  3. #include "stdlib.h"
  4. #include "string.h"
  5. #include "mxchipWNet_TypeDef.h"
  6. #include "stm32f2xx.h"

  7. #define AF_INET 2
  8. #define SOCK_STREAM 1
  9. #define SOCK_DGRM 2
  10. #define IPPROTO_TCP 6
  11. #define IPPROTO_UDP 17
  12. #define SOL_SOCKET   1
  13. #define INADDR_ANY   0
  14. #define INADDR_BROADCAST 0xFFFFFFFF


  15. #define u8 unsigned char
  16. #define u16 unsigned short
  17. #define u32 unsigned int


  18. #ifndef ssize_t
  19. #define ssize_t unsigned int
  20. #endif
  21.        

  22. //#ifndef size_t
  23. //#define size_t unsigned int
  24. //#endif

  25. typedef struct  _component_baseinfo_st{
  26.   char protocol_ver[32];
  27.   char hw_ver[32];
  28.   char sw_ver[32];
  29.   char product_id[32];
  30.   char product_date[32];
  31. } COMPONENT_BASEINFO_st;

  32. typedef struct _component_WIFIinfo_st{
  33.   COMPONENT_BASEINFO_st baseinfo;
  34.   char swlst[32];//eg:softap/wps
  35.   char securityt[32];//eg:wpa/wep/wpa2
  36.   char wkmode[32];//eg: b/g/n/a/bg/gn/bgn
  37. } COMPONENT_WIFIINFO_st;

  38. typedef struct _component_BTinfo_st{
  39.   COMPONENT_BASEINFO_st baseinfo;
  40.   int MFIflg;//if has MFI with CP 1-has ,0-none  
  41. } COMPONENT_BTINFO_st;

  42. typedef struct _component_NFCinfo_st{
  43.     COMPONENT_BASEINFO_st baseinfo;  
  44.     char nfc_model_no[32];//product model number  
  45.     char nfc_id[32];//product id  
  46.     char tag_type;//tag0:0,tag1:1,tag2:2,tag3:3  
  47.     char nfc_mode;//passive:0,active:1,bi_direction:2;  
  48. } COMPONENT_NFCINFO_st;

  49. struct sockaddr_t {
  50.    u16        s_type;
  51.    u16        s_port;
  52.    u32              s_ip;
  53.    u16        s_spares[6];  /* unused in TCP realm */
  54. } ;

  55. typedef struct in_addr {
  56.    u32 s_addr __attribute__ ((packed));        //fancpp add 2007.3.14 __packed, align byte
  57. } in_addr_t;


  58. struct timeval_t {
  59.         unsigned long                tv_sec;                /* seconds */
  60.         unsigned long                tv_usec;        /* microseconds */
  61. };

  62. typedef long time_t; /* 时间值time_t 为长整型的别名*/;

  63. typedef  struct  _timeval_st{
  64.     long tv_sec; /*1970年1月1日至今的秒数*/
  65.     long tv_hmsec; /* 1970年1月1日至今的百豪秒数*/
  66. }TIMEVAL_st;

  67. #define NULL 0

  68. typedef int socklen_t;

  69. typedef enum
  70. {
  71.     IRQ_TRIGGER_RISING_EDGE  = 0x1, /* Interrupt triggered at input signal's rising edge  */
  72.     IRQ_TRIGGER_FALLING_EDGE = 0x2, /* Interrupt triggered at input signal's falling edge */
  73.     IRQ_TRIGGER_BOTH_EDGES   = IRQ_TRIGGER_RISING_EDGE | IRQ_TRIGGER_FALLING_EDGE,
  74. } gpio_irq_trigger_t;

  75. typedef void (*gpio_irq_handler_t)( void* arg);

  76. typedef enum {
  77.         SO_REUSEADDR = 2,         /* Socket always support this option */
  78.         SO_BROADCAST = 6,                /* Socket always support this option */
  79.         SO_BLOCKMODE = 0x1000,  /* set socket as block/non-block mode, default is block mode */
  80.         SO_SNDTIMEO = 0x1005,        /* send timeout */
  81.         SO_RCVTIMEO =0x1006        ,        /* receive timeout */
  82.         SO_CONTIMEO =0x1007        ,        /* connect timeout */

  83.   SO_RDBUFLEN = 0x1008,
  84.   SO_WRBUFLEN = 0x1009,
  85. } SOCK_OPT_VAL;

  86. typedef struct _net_para {
  87.   char dhcp;
  88.         char ip[16]; // such as string  "192.168.1.1"
  89.         char gate[16];
  90.   char mask[16];
  91.         char dns[16];
  92.   char mac[16]; // such as string "7E0000001111"
  93.   char broadcastip[16];
  94. } net_para_st;


  95. typedef  struct  _ApList_str  
  96. {  
  97.     char ssid[32];  
  98.     char ApPower;  // min:0, max:100
  99. }ApList_str;


  100. typedef  struct  _UwtPara_str  
  101. {  
  102.   char ApNum;       //AP number
  103.   ApList_str * ApList;
  104. } UwtPara_str;  



  105. typedef struct _uart_get_str
  106. {
  107.     int BaudRate;    //The baud rate
  108.     char number;     //The number of data bits
  109.     char parity;     //The parity(0: none, 1:odd, 2:evn, default:0)
  110.     char StopBits;      //The number of stop bits
  111.     char FlowControl;    //support flow control is 1
  112. }uart_get_str;

  113. typedef struct _uart_set_str
  114. {
  115.     char UartName[8];    // the name of uart
  116.     int BaudRate;    //The baud rate
  117.     char number;     //The number of data bits
  118.     char parity;     //The parity(default NONE)
  119.     char StopBits;      //The number of stop bits
  120.     char FlowControl;    //support flow control is 1
  121. }uart_set_str;

  122. typedef struct _uart_str
  123. {
  124.         char baudrate;     //The baud rate, 0:9600, 1:19200, 2:38400, 3:57600, 4:115200, 5:230400, 6:460800, 7:921600
  125.         char databits;      //0:8, 1:9
  126.         char parity;       //The parity(default NONE)  0:none, 1:even parity, 2:odd parity
  127.         char stopbits;       //The number of stop bits ,  0:1, 1:0.5, 2:2, 3:1.5
  128. } uart_str;

  129. typedef struct _network_InitTypeDef_st
  130. {
  131.     char wifi_mode;    // SoftAp(0),sta(1)  
  132.     char wifi_ssid[32];
  133.     char wifi_key[32];
  134.     char local_ip_addr[16];
  135.     char net_mask[16];
  136.     char gateway_ip_addr[16];
  137.     char dnsServer_ip_addr[16];
  138.     char dhcpMode;       // disable(0), client mode(1), server mode(2)
  139.     char address_pool_start[16];
  140.     char address_pool_end[16];
  141.     int wifi_retry_interval;//sta reconnect interval, ms
  142. } network_InitTypeDef_st;

  143. typedef struct _sta_ap_state{
  144.     int is_connected;
  145.     int wifi_strength;
  146.     u8  ssid[32];
  147.     u8  bssid[6];
  148. }sta_ap_state_t;

  149. struct wifi_InitTypeDef
  150. {
  151.         u8 wifi_mode;                // adhoc mode(1), AP client mode(0), AP mode(2)
  152.         u8 wifi_ssid[32];
  153.         u8 wifi_key[32];
  154. };

  155. typedef enum {
  156.   MXCHIP_SUCCESS = 0,
  157.   MXCHIP_FAILED = -1,
  158.   MXCHIP_8782_INIT_FAILED = -2,
  159.   MXCHIP_SYS_ILLEGAL = -3,
  160.   MXCHIP_WIFI_JOIN_FAILED = -4,

  161.   MXCHIP_WIFI_UP = 1,
  162.   MXCHIP_WIFI_DOWN,

  163.   MXCHIP_UAP_UP,
  164.   MXCHIP_UAP_DOWN,
  165. } MxchipStatus;

  166. /* Upgrade iamge should save this table to flash */
  167. #pragma pack(1)
  168. typedef struct  _boot_table_t {
  169.         u32 start_address; // the address of the bin saved on flash.
  170.         u32 length; // file real length
  171.         u8 version[8];
  172.         u8 type; // B:bootloader, P:boot_table, A:application, D: 8782 driver
  173.         u8 upgrade_type; //u:upgrade,
  174.         u8 reserved[6];
  175. }boot_table_t;

  176. typedef struct _lib_config_t {
  177.     int tcp_buf_dynamic; // TCP socket buffer dynamic malloc. 1:enable 0:diaable
  178.                 int hw_watchdog; // Watchdag output: EMW3162->PC2, EMW3161->PB14. 1:enable 0:diaable
  179. }lib_config_t;

  180. enum {
  181.         SLEEP_UNIT_MS = 0,
  182.         SLEEP_UNIT_BEACON = 1,
  183. };

  184. #define FD_UART         1
  185. #define FD_USER_BEGIN   2
  186. #define FD_SETSIZE      1024 // MAX 1024 fd
  187. typedef unsigned long   fd_mask;

  188. #define NBBY    8               /* number of bits in a byte */
  189. #define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */


  190. #define howmany(x, y)   (((x) + ((y) - 1)) / (y))

  191. typedef struct fd_set {
  192.         fd_mask   fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  193. } fd_set;

  194. #define _fdset_mask(n)   ((fd_mask)1 << ((n) % NFDBITS))
  195. #define FD_SET(n, p)     ((p)->fds_bits[(n)/NFDBITS] |= _fdset_mask(n))
  196. #define FD_CLR(n, p)     ((p)->fds_bits[(n)/NFDBITS] &= ~_fdset_mask(n))
  197. #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & _fdset_mask(n))
  198. #define FD_ZERO(p)      memset(p, 0, sizeof(*(p)))

  199. #define MSG_DONTWAIT    0x40    /* Nonblocking io  */

  200. extern void lib_config(lib_config_t* conf);
  201. extern int setSslMaxlen(int len);
  202. extern int getSslMaxlen(void);
  203. extern void set_cert(const char *cert_pem, const char*private_key_pem);
  204. extern int setSSLmode(int enable, int sockfd);

  205. extern int SelectSupport(void);
  206. extern int tx_buf_size(int sockfd);

  207. extern int socket(int domain, int type, int protocol);
  208. extern int setsockopt(int sockfd, int level, int optname,const void *optval, socklen_t optlen);
  209. extern int bind(int sockfd, const struct sockaddr_t *addr, socklen_t addrlen);
  210. extern int connect(int sockfd, const struct sockaddr_t *addr, socklen_t addrlen);
  211. extern int listen(int sockfd, int backlog);
  212. extern int accept(int sockfd, struct sockaddr_t *addr, socklen_t *addrlen);
  213. extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval_t *timeout);
  214. extern ssize_t send(int sockfd, const void *buf, size_t len, int flags);
  215. extern ssize_t  sendto(int  sockfd,  const  void  *buf,  size_t  len,  int  flags,const  struct  sockaddr_t  *dest_addr,
  216.                                 socklen_t addrlen);
  217. extern ssize_t recv(int sockfd, void *buf, size_t len, int flags);
  218. extern ssize_t recvfrom(int  sockfd,  void  *buf,  size_t  len,  int  flags,struct  sockaddr_t  *src_addr,  socklen_t
  219.                                         *addrlen);
  220. extern int read(int sockfd, void *buf, size_t len);
  221. extern int write(int sockfd, void *buf, size_t len);
  222. extern int close(int fd);

  223. extern int GetUartPara (char *uart_name, uart_get_str * uart_para);
  224. extern int GetUartNum(char *uartname);
  225. extern int SetUartPara (uart_set_str *puartpara);
  226. extern int OpenUART(char*  uart_name);

  227. extern MxchipStatus mxchipInit(void);
  228. extern int StartNetwork(network_InitTypeDef_st* pNetworkInitPara);

  229. int getNetPara(net_para_st * pnetpara, WiFi_Interface iface);


  230. extern void mxchipTick(void);

  231. extern void mxchipStartScan(void);
  232. extern int StartScan(int interval);
  233. extern int StopScan(void);
  234. extern int CheckNetLink(sta_ap_state_t *ap_state);
  235. int ReallocIP(void);
  236. int gethostbyname(const char * name, u8 * ip_addr, u8 ipLength);
  237. u32 dns_request(char *hostname);

  238. extern int SetTimer(unsigned long ms, void (*psysTimerHandler)(void));

  239. /* User provide watch dog callback function */
  240. extern void WatchDog(void);

  241. extern int FlashGetInfo(int *flashadd,int len);
  242. extern int FlashRead(int flashadd,char *pbuf,int len);
  243. extern int FlashWrite(int flashadd,char *pbuf,int len);
  244. extern int FlashErase(int flashadd, int erase_bytelen);
  245. extern MxchipStatus newimage_write(int offset , int len , char *pbuf);

  246. extern int sleep(int seconds);
  247. extern int msleep(int mseconds);

  248. extern u16 ntohs(u16 n);
  249. extern u16 htons(u16 n);
  250. extern u32 ntohl(u32 n);
  251. extern u32 htonl(u32 n);

  252. /* Convert an ip address string in dotted decimal format to  its binary representation.*/
  253. extern u32 inet_addr(char *s);

  254. /* Convert a binary ip address to its dotted decimal format.
  255. PARAMETER1 's':  location to place the dotted decimal string.  This must be an array of at least 16 bytes.
  256. PARAMETER2 'x':  ip address to convert.

  257. RETURN VALUE:  returns 's' .
  258. */
  259. extern char *inet_ntoa( char *s, u32 x );

  260. extern void enable_ps_mode(int unit_type, int unitcast_ms, int multicast_ms);

  261. extern void disable_ps_mode(void);

  262. extern void system_reload(void);

  263. /* This is function is used to caclute the md5 value for the input buffer
  264.   * input: the source buffer;
  265.   * len: the length of the source buffer;
  266.   * output: point the output buffer, should be a 16 bytes buffer
  267.   */
  268. extern void md5_hex(u8 *input, u32 len, u8 *output);

  269. int wifi_power_down(void);
  270. int wifi_power_up(void);
  271. int wlan_disconnect(void);
  272. int sta_disconnect(void);
  273. int uap_stop(void);

  274. int OpenConfigmodeWPS(int timeout);
  275. int CloseConfigmodeWPS(void);

  276. int OpenEasylink(int timeout);
  277. int CloseEasylink(void);


  278. int OpenBT(int timeout);
  279. int CloseBT(void);
  280. int SetBTName(char *name);

  281. int SetBTpin(char *pin, int enable);

  282. int SetBTboundleID(char*boundleID);
  283. int SetBTseedID(char* seedID);
  284. int SetBTsdkProto(char*sdkproto);

  285. int GetBTArg(char *name, char *pin, int *enable_pin, char *boundleID);
  286. int SetBT_SearchAppPara(char *boundleID, char *seedId, char *SdkProtocolToken);

  287. /* devlist return mac[4][6], return 4 mac address, last_dev_index is the last connected dev index (0~3)*/
  288. int GetBTDevlist(char *devlist, u8 *last_dev_index);

  289. int CheckComponentBT(COMPONENT_BTINFO_st *pst);


  290. int CheckComponentWIFI(COMPONENT_WIFIINFO_st *pst);

  291. int CheckComponentNFC(COMPONENT_NFCINFO_st * st);
  292. int OpenConfigmodeNFC(int timeout);
  293. int CloseConfigmodeNFC(void);

  294. void RptConfigmodeRslt(network_InitTypeDef_st *nwkpara);

  295. void ApListCallback(UwtPara_str *pApList);

  296. time_t user_time(TIMEVAL_st *t);

  297. void ps_enable(void);
  298. void ps_disable(void);

  299. void set_tcp_keepalive(int num, int seconds);
  300. void get_tcp_keepalive(int *num, int *seconds);

  301. int gpio_irq_enable ( GPIO_TypeDef* gpio_port, uint8_t gpio_pin_number, gpio_irq_trigger_t trigger, gpio_irq_handler_t handler, void* arg );
  302. int gpio_irq_disable( GPIO_TypeDef* gpio_port, uint8_t gpio_pin_number );

  303. int get_tcp_clients(void);
  304. void memory_status(int *total_free, int *max_len);
  305. void get_malloc_list(void (*debug_mem)(u32 p, int len));
  306. void malloc_list_mem(u8 *memory_tbl, int size);


  307. // user provide callback function
  308. void WatchDog(void);
  309. void WifiStatusHandler(int status);
  310. void RptConfigmodeRslt(network_InitTypeDef_st *nwkpara);
  311. void NetCallback(net_para_st *pnet);
  312. void ApListCallback(UwtPara_str *pApList);
  313. void dns_ip_set(u8 *hostname, u32 ip);
  314. void socket_connected(int fd);

  315. void NoOS_systick_irq(void);
  316. void gpio_irq(void);
  317. void sdio_irq(void);
  318. void dma_irq(void);
  319. void bt_uart_irq(void);


  320. /* transform src string to hex mode
  321.   * example: "aabbccddee" => 0xaabbccddee
  322.   * each char in the string must 0~9 a~f A~F, otherwise return 0
  323.   * return the real obuf length
  324.   */
  325. extern unsigned int str2hex(unsigned char *ibuf, unsigned char *obuf, unsigned int olen);

  326. #endif
复制代码


此帖出自RF/无线论坛
点赞 关注
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
快速回复 返回顶部 返回列表