mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 10:17:30 +02:00
Test: Initial version of modem tests
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS esp_netif_linux.c
|
||||
INCLUDE_DIRS include
|
||||
REQUIRES esp_system_protocols_linux)
|
@ -0,0 +1,68 @@
|
||||
//
|
||||
// Created by david on 2/7/21.
|
||||
//
|
||||
#include<stdio.h>
|
||||
|
||||
#include "esp_netif.h"
|
||||
#include "esp_err.h"
|
||||
#include<string.h> //strlen
|
||||
#include<sys/socket.h>
|
||||
#include<arpa/inet.h> //inet_addr
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
|
||||
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info)
|
||||
{
|
||||
ESP_IPADDR4_INIT(&ip_info->ip, 1,2,3,4);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6)
|
||||
{
|
||||
|
||||
struct ifaddrs *addrs, *tmp;
|
||||
getifaddrs(&addrs);
|
||||
tmp = addrs;
|
||||
|
||||
while (tmp)
|
||||
{
|
||||
// if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET)
|
||||
// {
|
||||
// struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
|
||||
// printf("%s: %s\n", tmp->ifa_name, inet_ntoa(pAddr->sin_addr));
|
||||
// } else
|
||||
|
||||
if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) {
|
||||
char addr[64];
|
||||
struct sockaddr_in6 *pAddr = (struct sockaddr_in6 *)tmp->ifa_addr;
|
||||
inet_ntop(AF_INET6, &pAddr->sin6_addr, addr, sizeof(addr) );
|
||||
printf("%s: %s\n", tmp->ifa_name, addr);
|
||||
inet6_addr_to_ip6addr(if_ip6, &pAddr->sin6_addr);
|
||||
}
|
||||
|
||||
tmp = tmp->ifa_next;
|
||||
}
|
||||
|
||||
freeifaddrs(addrs);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif)
|
||||
{
|
||||
char * ifname = "enp1s0";
|
||||
uint32_t interfaceIndex = if_nametoindex(ifname);
|
||||
printf("%s: %d\n", ifname, interfaceIndex);
|
||||
return interfaceIndex;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
//
|
||||
// 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 _HOST_ESP_NETIF_H_
|
||||
#define _HOST_ESP_NETIF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_netif_ip_addr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
struct esp_netif_obj {};
|
||||
|
||||
typedef struct esp_netif_driver_base_s {
|
||||
esp_err_t (*post_attach)(esp_netif_t *netif, void* h);
|
||||
esp_netif_t *netif;
|
||||
} esp_netif_driver_base_t;
|
||||
|
||||
struct esp_netif_driver_ifconfig {
|
||||
void* handle;
|
||||
esp_err_t (*transmit)(void *h, void *buffer, size_t len);
|
||||
esp_err_t (*transmit_wrap)(void *h, void *buffer, size_t len, void *netstack_buffer);
|
||||
void (*driver_free_rx_buffer)(void *h, void* buffer);
|
||||
};
|
||||
|
||||
typedef struct esp_netif_obj esp_netif_t;
|
||||
|
||||
/** @brief Status of DHCP client or DHCP server */
|
||||
typedef enum {
|
||||
ESP_NETIF_DHCP_INIT = 0, /**< DHCP client/server is in initial state (not yet started) */
|
||||
ESP_NETIF_DHCP_STARTED, /**< DHCP client/server has been started */
|
||||
ESP_NETIF_DHCP_STOPPED, /**< DHCP client/server has been stopped */
|
||||
ESP_NETIF_DHCP_STATUS_MAX
|
||||
} esp_netif_dhcp_status_t;
|
||||
|
||||
|
||||
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key);
|
||||
|
||||
esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info);
|
||||
|
||||
esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status);
|
||||
|
||||
esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6);
|
||||
int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif);
|
||||
|
||||
void esp_netif_action_connected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
|
||||
void esp_netif_action_disconnected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data);
|
||||
|
||||
#endif // _HOST_ESP_NETIF_H_
|
@ -0,0 +1,182 @@
|
||||
// Copyright 2015-2019 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_NETIF_IP_ADDR_H_
|
||||
#define _ESP_NETIF_IP_ADDR_H_
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define esp_netif_htonl(x) ((uint32_t)(x))
|
||||
#else
|
||||
#define esp_netif_htonl(x) ((((x) & (uint32_t)0x000000ffUL) << 24) | \
|
||||
(((x) & (uint32_t)0x0000ff00UL) << 8) | \
|
||||
(((x) & (uint32_t)0x00ff0000UL) >> 8) | \
|
||||
(((x) & (uint32_t)0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
#define esp_netif_ip4_makeu32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \
|
||||
((uint32_t)((b) & 0xff) << 16) | \
|
||||
((uint32_t)((c) & 0xff) << 8) | \
|
||||
(uint32_t)((d) & 0xff))
|
||||
|
||||
// Access address in 16-bit block
|
||||
#define ESP_IP6_ADDR_BLOCK1(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK2(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[0])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK3(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK4(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[1])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK5(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK6(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[2])) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK7(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
|
||||
#define ESP_IP6_ADDR_BLOCK8(ip6addr) ((uint16_t)((esp_netif_htonl((ip6addr)->addr[3])) & 0xffff))
|
||||
|
||||
#define IPSTR "%d.%d.%d.%d"
|
||||
#define esp_ip4_addr_get_byte(ipaddr, idx) (((const uint8_t*)(&(ipaddr)->addr))[idx])
|
||||
#define esp_ip4_addr1(ipaddr) esp_ip4_addr_get_byte(ipaddr, 0)
|
||||
#define esp_ip4_addr2(ipaddr) esp_ip4_addr_get_byte(ipaddr, 1)
|
||||
#define esp_ip4_addr3(ipaddr) esp_ip4_addr_get_byte(ipaddr, 2)
|
||||
#define esp_ip4_addr4(ipaddr) esp_ip4_addr_get_byte(ipaddr, 3)
|
||||
|
||||
|
||||
#define esp_ip4_addr1_16(ipaddr) ((uint16_t)esp_ip4_addr1(ipaddr))
|
||||
#define esp_ip4_addr2_16(ipaddr) ((uint16_t)esp_ip4_addr2(ipaddr))
|
||||
#define esp_ip4_addr3_16(ipaddr) ((uint16_t)esp_ip4_addr3(ipaddr))
|
||||
#define esp_ip4_addr4_16(ipaddr) ((uint16_t)esp_ip4_addr4(ipaddr))
|
||||
|
||||
#define IP2STR(ipaddr) esp_ip4_addr1_16(ipaddr), \
|
||||
esp_ip4_addr2_16(ipaddr), \
|
||||
esp_ip4_addr3_16(ipaddr), \
|
||||
esp_ip4_addr4_16(ipaddr)
|
||||
|
||||
#define IPV6STR "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
|
||||
|
||||
#define IPV62STR(ipaddr) ESP_IP6_ADDR_BLOCK1(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK2(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK3(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK4(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK5(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK6(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK7(&(ipaddr)), \
|
||||
ESP_IP6_ADDR_BLOCK8(&(ipaddr))
|
||||
|
||||
#define ESP_IPADDR_TYPE_V4 0U
|
||||
#define ESP_IPADDR_TYPE_V6 6U
|
||||
#define ESP_IPADDR_TYPE_ANY 46U
|
||||
|
||||
#define ESP_IP4TOUINT32(a,b,c,d) (((uint32_t)((a) & 0xffU) << 24) | \
|
||||
((uint32_t)((b) & 0xffU) << 16) | \
|
||||
((uint32_t)((c) & 0xffU) << 8) | \
|
||||
(uint32_t)((d) & 0xffU))
|
||||
|
||||
#define ESP_IP4TOADDR(a,b,c,d) esp_netif_htonl(ESP_IP4TOUINT32(a, b, c, d))
|
||||
|
||||
// new definitions
|
||||
#define ESP_IPADDR4_INIT(ipaddr, a,b,c,d) (ipaddr)->addr = ESP_IP4TOADDR(a,b,c,d)
|
||||
#define ESP_IP6TOADDR(a, b, c, d) { { { { a, b, c, d } , 0 } }, ESP_IPADDR_TYPE_V6 }
|
||||
|
||||
// TODO: use esp-netif instead of lwip API
|
||||
#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
|
||||
#define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
|
||||
#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
|
||||
#define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
|
||||
#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == ESP_IPADDR_TYPE_V6)
|
||||
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
|
||||
#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
|
||||
(dest).addr[1] = (src).addr[1]; \
|
||||
(dest).addr[2] = (src).addr[2]; \
|
||||
(dest).addr[3] = (src).addr[3];}while(0)
|
||||
|
||||
#define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
|
||||
ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
|
||||
ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
|
||||
|
||||
|
||||
#define IP_MULTICAST(a) IN_CLASSD(a)
|
||||
|
||||
#define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & htonl(0xff000000UL)) == htonl(0xff000000UL))
|
||||
#define IP6_NO_ZONE 0
|
||||
#define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = IP6_NO_ZONE)
|
||||
|
||||
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \
|
||||
(target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \
|
||||
(target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \
|
||||
(target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3];}
|
||||
|
||||
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \
|
||||
(target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \
|
||||
(target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \
|
||||
(target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \
|
||||
ip6_addr_clear_zone(target_ip6addr);}
|
||||
|
||||
|
||||
struct esp_ip6_addr {
|
||||
uint32_t addr[4];
|
||||
uint8_t zone;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct esp_ip4_addr {
|
||||
uint32_t addr;
|
||||
};
|
||||
|
||||
typedef struct esp_ip4_addr esp_ip4_addr_t;
|
||||
|
||||
typedef struct esp_ip6_addr esp_ip6_addr_t;
|
||||
|
||||
typedef struct _ip_addr {
|
||||
union {
|
||||
esp_ip6_addr_t ip6;
|
||||
esp_ip4_addr_t ip4;
|
||||
} u_addr;
|
||||
uint8_t type;
|
||||
} esp_ip_addr_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_IP6_ADDR_IS_UNKNOWN,
|
||||
ESP_IP6_ADDR_IS_GLOBAL,
|
||||
ESP_IP6_ADDR_IS_LINK_LOCAL,
|
||||
ESP_IP6_ADDR_IS_SITE_LOCAL,
|
||||
ESP_IP6_ADDR_IS_UNIQUE_LOCAL,
|
||||
ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6
|
||||
} esp_ip6_addr_type_t;
|
||||
|
||||
typedef struct {
|
||||
esp_ip4_addr_t ip; /**< Interface IPV4 address */
|
||||
esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */
|
||||
esp_ip4_addr_t gw; /**< Interface IPV4 gateway address */
|
||||
} esp_netif_ip_info_t;
|
||||
|
||||
typedef struct {
|
||||
esp_ip6_addr_t ip; /**< Interface IPV6 address */
|
||||
} esp_netif_ip6_info_t;
|
||||
|
||||
/**
|
||||
* @brief Get the IPv6 address type
|
||||
*
|
||||
* @param[in] ip6_addr IPv6 type
|
||||
*
|
||||
* @return IPv6 type in form of enum esp_ip6_addr_type_t
|
||||
*/
|
||||
esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_ESP_NETIF_IP_ADDR_H_
|
@ -0,0 +1,22 @@
|
||||
// Copyright 2021 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_NETIF_PPP_H_
|
||||
#define _ESP_NETIF_PPP_H_
|
||||
|
||||
#define NETIF_PP_PHASE_OFFSET 0x100
|
||||
|
||||
|
||||
#endif //_ESP_NETIF_PPP_H_
|
Reference in New Issue
Block a user