mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-22 17:47:04 +08:00
feat(esp8266): Remove esp_socket to save flash and ram
This commit is contained in:
@ -1,38 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_MODULE_H
|
||||
#define _ESP_MODULE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __EXPORT_SYMBOL_NAME(sec) "ksymatab"sec
|
||||
|
||||
#define __EXPORT_SYMBOL(sym, sec) \
|
||||
static const typeof(sym) *__ksymtab_##sym \
|
||||
__attribute__((used,section("ksymatab"sec))) \
|
||||
= &sym
|
||||
|
||||
#define __DECLARE_SYMBOL_NAME(sec) __EXPORT_SYMBOL_NAME(sec)
|
||||
|
||||
#define __DECLARE_SYMBOL(type, sym, sec) \
|
||||
static const type sym __attribute__((used,section("ksymatab"sec),aligned(sizeof(void *))))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_MODULE_H */
|
@ -1,260 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_SOCKET_H
|
||||
#define _ESP_SOCKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_aio.h"
|
||||
#include "esp_module.h"
|
||||
#include "net/if_packet.h"
|
||||
#include "net/if_socket.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* used for socket link */
|
||||
#define ESP_SOCKET_METHOD_BASENAME "esp_socket"
|
||||
#define ESP_SOCKET_METHOD_NAME(sec) __DECLARE_SYMBOL_NAME(ESP_SOCKET_METHOD_BASENAME)
|
||||
#define ESP_SOCKET_METHOD_DECLARE(sym) __DECLARE_SYMBOL(esp_socket_method_t, sym, ESP_SOCKET_METHOD_BASENAME)
|
||||
|
||||
#ifndef socklen_t
|
||||
typedef uint32_t socklen_t;
|
||||
#endif
|
||||
|
||||
#define esp_socket_va_start(va, arg) va = (va_list)arg
|
||||
|
||||
/*
|
||||
* socket async event
|
||||
*/
|
||||
enum esp_socket_event_type {
|
||||
ESP_SOCKET_CONNECT_EVENT = 0,
|
||||
ESP_SOCKET_ACCEPT_EVENT = ESP_SOCKET_CONNECT_EVENT,
|
||||
ESP_SOCKET_RECV_EVENT = 1,
|
||||
ESP_SOCKET_ERROR_EVENT = 2,
|
||||
|
||||
ESP_SOCKET_MAX_EVENT
|
||||
};
|
||||
|
||||
/*
|
||||
* socket information object
|
||||
*/
|
||||
typedef struct esp_socket_info {
|
||||
int domain;
|
||||
int type;
|
||||
int protocol;
|
||||
} esp_socket_info_t;
|
||||
|
||||
/*
|
||||
* socket method object
|
||||
*/
|
||||
typedef struct esp_socket_method {
|
||||
/*
|
||||
* socket method name
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/*
|
||||
* @brief open lowlevel socket module
|
||||
*
|
||||
* @param info socket information
|
||||
*
|
||||
* @return return lowlevel socket index if successfully, otherwise return NULL
|
||||
* and you can get the real fail reason by "errno"
|
||||
*/
|
||||
void* (*open)(esp_socket_info_t *info);
|
||||
|
||||
/*
|
||||
* @brief send a block of data asynchronously and receive result by callback function
|
||||
*
|
||||
* @param index lowlevel index
|
||||
* @param aio asynchronous I/O controlling block
|
||||
* @param to target address with lowlevel address data format
|
||||
* @param len target address data length
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int (*aio_sendto)(void *index, esp_aio_t *aio, const struct sockaddr_ll *to, socklen_t len);
|
||||
|
||||
/*
|
||||
* @brief register an event and its callback function to lowlevel socket module
|
||||
*
|
||||
* @param index lowlevel index
|
||||
* @param event asynchronous I/O event
|
||||
* @param cb callback function
|
||||
* @param arg callback function parameter
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int (*aio_event)(void *index, unsigned int event, esp_aio_cb_t cb, void *arg);
|
||||
|
||||
/*
|
||||
* @brief free buffer taken from event callback
|
||||
*
|
||||
* @param index lowlevel index
|
||||
* @param pbuf buffer pointer
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int (*free_pbuf)(void *index, void *pbuf);
|
||||
|
||||
/*
|
||||
* @brief send request command to lowlevel socket module and get the result synchronously
|
||||
*
|
||||
* @param index lowlevel index
|
||||
* @param cmd request command
|
||||
* @param arg start address to variable parameters
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int (*ioctl)(void *index, unsigned int cmd, void *arg);
|
||||
|
||||
/*
|
||||
* @brief close lowlevel socket module
|
||||
*
|
||||
* @param index lowlevel index
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int (*close)(void *index);
|
||||
} esp_socket_method_t;
|
||||
|
||||
/*
|
||||
* @brief free an aio control block by calling the callback function
|
||||
*
|
||||
* @param aio asynchronous I/O controlling block
|
||||
* @param aio data handling result
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static inline void esp_aio_free(esp_aio_t *aio, int status)
|
||||
{
|
||||
if (aio->cb) {
|
||||
aio->ret = status;
|
||||
aio->cb(aio);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief drop an aio control block by disable "pbuf" and "cb"
|
||||
* and then the aio control block has no meaning
|
||||
*
|
||||
* @param aio asynchronous I/O controlling block
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static inline void esp_aio_drop(esp_aio_t *aio)
|
||||
{
|
||||
aio->pbuf = NULL;
|
||||
aio->cb = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief create a socket file description
|
||||
*
|
||||
* @param domain protocal domain and it must be "AF_PACKET" now
|
||||
* @param type socket type and it must be "SOCK_RAW" now
|
||||
* @param protocol target protocol and it must be "ETH_P_ALL" now
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*
|
||||
* @note using "AF_PACKET", "SOCK_RAW" and "ETH_P_ALL" means that you receive and send full
|
||||
* ethernet II type message with full message head: " destination mac | source mac | type"
|
||||
*/
|
||||
int esp_socket(int domain, int type, int protocol);
|
||||
|
||||
/*
|
||||
* @brief send a block of data asynchronously and receive result by callback function
|
||||
*
|
||||
* @param aio asynchronous I/O controlling block
|
||||
* @param to target address with lowlevel address data format
|
||||
* @param len target address data length
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_aio_sendto(esp_aio_t *aio, const struct sockaddr_ll *to, socklen_t len);
|
||||
|
||||
/*
|
||||
* @brief register an event and its callback function to target of file description
|
||||
*
|
||||
* @param fd file description
|
||||
* @param event asynchronous I/O event
|
||||
* @param cb callback function
|
||||
* @param arg callback function parameter
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_aio_event(int fd, unsigned int event, esp_aio_cb_t cb, void *arg);
|
||||
|
||||
/*
|
||||
* @brief lowlevel socket module upload event and its data
|
||||
*
|
||||
* @param index lowlevel index
|
||||
* @param info socket information
|
||||
* @param event asynchronous I/O event
|
||||
* @param aio asynchronous I/O controlling block
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_upload_event(void *index, esp_socket_info_t *info, unsigned int event, esp_aio_data_t *aio_data);
|
||||
|
||||
/*
|
||||
* @brief free buffer taken from event callback
|
||||
*
|
||||
* @param fd file description
|
||||
* @param pbuf buffer pointer
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_free_pbuf(int fd, void *pbuf);
|
||||
|
||||
/*
|
||||
* @brief send request command to target by file description and get the result synchronously
|
||||
*
|
||||
* @param fd file description
|
||||
* @param cmd request command
|
||||
* @param ... realy command parameters and it must be related to realy object of lowlevel
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_ioctl(int fd, unsigned int cmd, ...);
|
||||
|
||||
/*
|
||||
* @brief close target of file description
|
||||
*
|
||||
* @param fd file description
|
||||
*
|
||||
* @return return 0 if successfully, otherwise return -1 and you can get the real fail
|
||||
* reason by "errno"
|
||||
*/
|
||||
int esp_close(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_SOCKET_H */
|
@ -63,6 +63,49 @@ typedef void (*wifi_sta_rx_probe_req_t)(const uint8_t *frame, int len, int rssi)
|
||||
*/
|
||||
esp_err_t esp_wifi_set_sta_rx_probe_req(wifi_sta_rx_probe_req_t cb);
|
||||
|
||||
/**
|
||||
* @brief free the rx buffer which allocated by wifi driver
|
||||
*
|
||||
* @param void* buffer: rx buffer pointer
|
||||
*/
|
||||
void esp_wifi_internal_free_rx_buffer(void* buffer);
|
||||
|
||||
/**
|
||||
* @brief transmit the buffer via wifi driver
|
||||
*
|
||||
* @param wifi_interface_t wifi_if : wifi interface id
|
||||
* @param void *buffer : the buffer to be tansmit
|
||||
* @param uint16_t len : the length of buffer
|
||||
*
|
||||
* @return
|
||||
* - ERR_OK : Successfully transmit the buffer to wifi driver
|
||||
* - ERR_MEM : Out of memory
|
||||
* - ERR_IF : WiFi driver error
|
||||
* - ERR_ARG : Invalid argument
|
||||
*/
|
||||
int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, uint16_t len);
|
||||
|
||||
/**
|
||||
* @brief The WiFi RX callback function
|
||||
*
|
||||
* Each time the WiFi need to forward the packets to high layer, the callback function will be called
|
||||
*/
|
||||
typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
|
||||
|
||||
/**
|
||||
* @brief Set the WiFi RX callback
|
||||
*
|
||||
* @attention 1. Currently we support only one RX callback for each interface
|
||||
*
|
||||
* @param wifi_interface_t ifx : interface
|
||||
* @param wifi_rxcb_t fn : WiFi RX callback
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : succeed
|
||||
* - others : fail
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _IF_PACKET_H
|
||||
#define _IF_PACKET_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* socket II type address used by low-level module whose address is base on MAC address
|
||||
*
|
||||
* Note: Now it just support 802.3 and 802.11 protocol, so only "sll_addr" works here
|
||||
*/
|
||||
struct sockaddr_ll {
|
||||
unsigned short sll_family; // it must be AF_PACKET
|
||||
unsigned short sll_protocol; // physics level protocol
|
||||
int sll_ifindex; // interface index not socket ID
|
||||
unsigned short sll_hatype; // ARP hardware address type
|
||||
unsigned char sll_pkttype; // packet type
|
||||
unsigned char sll_halen; // hardware address length
|
||||
unsigned char sll_addr[8]; // address data
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _IF_PACKET_H */
|
@ -1,76 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _IF_ETHER_H
|
||||
#define _IF_ETHER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* undefine some global macro
|
||||
*/
|
||||
#undef ETH_P_ALL
|
||||
#undef ETH_P_ARP
|
||||
#undef ETH_P_IP
|
||||
|
||||
#undef AF_PACKET
|
||||
|
||||
#undef SOCK_RAW
|
||||
|
||||
/*
|
||||
* socket domain
|
||||
*/
|
||||
#define AF_PACKET 0
|
||||
|
||||
/*
|
||||
* socket type
|
||||
*/
|
||||
#define SOCK_RAW 0
|
||||
|
||||
/*
|
||||
* use 16(2^4) type for socket
|
||||
*/
|
||||
#define IF_SOCK_SHIFT 4
|
||||
#define IF_SOCK_TYPE(d) (d & 0xf)
|
||||
#define IF_SOCK_DATA(t, s) ((1 << (s + IF_SOCK_SHIFT)) + t)
|
||||
|
||||
enum if_sock_type {
|
||||
IF_SOCK_ETH = 0,
|
||||
IF_SOCK_WIFI,
|
||||
|
||||
IF_SOCK_MAX,
|
||||
};
|
||||
|
||||
#define IF_ETH_DATA(s) IF_SOCK_DATA(IF_SOCK_ETH, s)
|
||||
#define IF_WIFI_DATA(s) IF_SOCK_DATA(IF_SOCK_WIFI, s)
|
||||
|
||||
/*
|
||||
* socket protocol
|
||||
*/
|
||||
#define ETH_P_IP IF_ETH_DATA(0)
|
||||
#define ETH_P_ARP IF_ETH_DATA(1)
|
||||
#define ETH_P_ALL ETH_P_IP | ETH_P_ARP
|
||||
|
||||
#define WIFI_P_MNG IF_WIFI_DATA(0)
|
||||
#define WIFI_P_CTL IF_WIFI_DATA(1)
|
||||
#define WIFI_P_DAT IF_WIFI_DATA(2)
|
||||
#define WIFI_P_ALL WIFI_P_MNG | WIFI_P_CTL | WIFI_P_DAT
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _IF_ETHER_H */
|
@ -1,46 +0,0 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _SOCKIO_H
|
||||
#define _SOCKIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* espressif specific socket ioctls */
|
||||
#define SIOESPSTART 0x5500 /* start of espressif specific code */
|
||||
|
||||
/* routing table calls. */
|
||||
#define SIOCADDRT 0x890B /* add routing table entry */
|
||||
#define SIOCDELRT 0x890C /* delete routing table entry */
|
||||
#define SIOCRTMSG 0x890D /* call to routing system */
|
||||
|
||||
/* socket configuration controls. */
|
||||
#define SIOCGIFADDR 0x8915 /* get PA address */
|
||||
#define SIOCSIFADDR 0x8916 /* set PA address */
|
||||
#define SIOCGIFBRDADDR 0x8919 /* get broadcast PA address */
|
||||
#define SIOCSIFBRDADDR 0x891a /* set broadcast PA address */
|
||||
#define SIOCGIFNETMASK 0x891b /* get network PA mask */
|
||||
#define SIOCSIFNETMASK 0x891c /* set network PA mask */
|
||||
#define SIOCSIFHWADDR 0x8924 /* set hardware address */
|
||||
#define SIOCGIFHWADDR 0x8927 /* Get hardware address */
|
||||
#define SIOCGIFINDEX 0x8933 /* name -> if_index mapping */
|
||||
#define SIOGIFINDEX SIOCGIFINDEX /* misprint compatibility :-) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SOCKIO_H */
|
Reference in New Issue
Block a user