mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/dhcps_more_client_info' into 'master'
lw-IP: Add more client's infor to dhcp server cb Closes IDFGH-5839 See merge request espressif/esp-idf!16433
This commit is contained in:
commit
5dcd630444
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -136,6 +136,7 @@ typedef struct {
|
||||
/** Event structure for IP_EVENT_AP_STAIPASSIGNED event */
|
||||
typedef struct {
|
||||
esp_ip4_addr_t ip; /*!< IP address which was assigned to the station */
|
||||
uint8_t mac[6]; /*!< MAC address of the connected client */
|
||||
} ip_event_ap_staipassigned_t;
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -764,14 +764,14 @@ esp_err_t esp_netif_recv_hook_detach(esp_netif_t *esp_netif)
|
||||
#endif // CONFIG_ESP_NETIF_L2_TAP
|
||||
|
||||
#if ESP_DHCPS
|
||||
static void esp_netif_dhcps_cb(u8_t client_ip[4])
|
||||
static void esp_netif_dhcps_cb(uint8_t ip[4], uint8_t mac[6])
|
||||
{
|
||||
ESP_LOGI(TAG, "DHCP server assigned IP to a station, IP is: %d.%d.%d.%d",
|
||||
client_ip[0], client_ip[1], client_ip[2], client_ip[3]);
|
||||
ip_event_ap_staipassigned_t evt;
|
||||
ip_event_ap_staipassigned_t evt = { 0 };
|
||||
memcpy((char *)&evt.ip.addr, (char *)ip, sizeof(evt.ip.addr));
|
||||
memcpy((char *)&evt.mac, mac, sizeof(evt.mac));
|
||||
ESP_LOGI(TAG, "DHCP server assigned IP to a station, IP is: " IPSTR, IP2STR(&evt.ip));
|
||||
ESP_LOGD(TAG, "Client's MAC: %x:%x:%x:%x:%x:%x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
memset(&evt, 0, sizeof(ip_event_ap_staipassigned_t));
|
||||
memcpy((char *)&evt.ip.addr, (char *)client_ip, sizeof(evt.ip.addr));
|
||||
int ret = esp_event_send_internal(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &evt, sizeof(evt), 0);
|
||||
if (ESP_OK != ret) {
|
||||
ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_AP_STAIPASSIGNED (%x)", ret);
|
||||
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2016 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.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
//#include "esp_common.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -690,7 +682,7 @@ static void send_ack(struct dhcps_msg *m, u16_t len)
|
||||
#endif
|
||||
|
||||
if (SendAck_err_t == ERR_OK) {
|
||||
dhcps_cb(m->yiaddr);
|
||||
dhcps_cb(m->yiaddr, m->chaddr);
|
||||
}
|
||||
|
||||
if (p->ref != 0) {
|
||||
@ -963,6 +955,7 @@ static void handle_dhcp(void *arg,
|
||||
u16_t dhcps_msg_cnt = 0;
|
||||
u8_t *p_dhcps_msg = NULL;
|
||||
u8_t *data;
|
||||
s16_t state;
|
||||
|
||||
#if DHCPS_DEBUG
|
||||
DHCPS_LOG("dhcps: handle_dhcp-> receive a packet\n");
|
||||
@ -1034,7 +1027,12 @@ static void handle_dhcp(void *arg,
|
||||
DHCPS_LOG("dhcps: handle_dhcp-> parse_msg(p)\n");
|
||||
#endif
|
||||
|
||||
switch (parse_msg(pmsg_dhcps, tlen - 240)) {
|
||||
state = parse_msg(pmsg_dhcps, tlen - 240);
|
||||
#ifdef LWIP_HOOK_DHCPS_POST_STATE
|
||||
state = LWIP_HOOK_DHCPS_POST_STATE(pmsg_dhcps, malloc_len, state);
|
||||
#endif /* LWIP_HOOK_DHCPS_POST_STATE */
|
||||
|
||||
switch (state) {
|
||||
case DHCPS_STATE_OFFER://1
|
||||
#if DHCPS_DEBUG
|
||||
DHCPS_LOG("dhcps: handle_dhcp-> DHCPD_STATE_OFFER\n");
|
||||
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2016 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.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __DHCPS_H__
|
||||
#define __DHCPS_H__
|
||||
|
||||
@ -53,6 +45,21 @@ enum dhcps_offer_option{
|
||||
OFFER_END
|
||||
};
|
||||
|
||||
/** @brief DHCP server's description of compile time configuration values in dhcpserver.c
|
||||
*
|
||||
* - DHCPS_DEBUG: Prints very detailed debug messages if set to 1, hardcoded to 0
|
||||
* - USE_CLASS_B_NET: Use class B network mask if enabled, not-defined (could be enabled as CC_FLAGS)
|
||||
* - MAX_STATION_NUM: Maximum number of clients, set to Kconfig value CONFIG_LWIP_DHCPS_MAX_STATION_NUM
|
||||
* - LWIP_HOOK_DHCPS_POST_STATE: Used to inject user code after parsing DHCP message, not defined
|
||||
* - could be enabled in lwipopts.h or via CC_FLAGS
|
||||
* - basic usage of the hook to print hex representation of the entire option field is below:
|
||||
* #define LWIP_HOOK_DHCPS_POST_STATE(msg, len, state) \
|
||||
* ({ s16_t ret = state; if (state == DHCPS_STATE_ACK) { ESP_LOG_BUFFER_HEXDUMP("DHCPS",msg->options, 312, ESP_LOG_INFO);} ret; })
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Definitions related to lease time, units and limits
|
||||
*/
|
||||
#define DHCPS_COARSE_TIMER_SECS 1
|
||||
#define DHCPS_MAX_LEASE 0x64
|
||||
#define DHCPS_LEASE_TIME_DEF (120)
|
||||
@ -74,7 +81,7 @@ typedef struct {
|
||||
dhcps_lease_t dhcps_poll;
|
||||
} dhcps_options_t;
|
||||
|
||||
typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
|
||||
typedef void (*dhcps_cb_t)(u8_t client_ip[4], u8_t client_mac[6]);
|
||||
|
||||
static inline bool dhcps_router_enabled (dhcps_offer_t offer)
|
||||
{
|
||||
|
@ -1195,11 +1195,9 @@ components/linux/include/sys/queue.h
|
||||
components/log/esp_log_private.h
|
||||
components/log/host_test/log_test/main/log_test.cpp
|
||||
components/log/log_linux.c
|
||||
components/lwip/apps/dhcpserver/dhcpserver.c
|
||||
components/lwip/apps/ping/esp_ping.c
|
||||
components/lwip/apps/ping/ping.c
|
||||
components/lwip/apps/sntp/sntp.c
|
||||
components/lwip/include/apps/dhcpserver/dhcpserver.h
|
||||
components/lwip/include/apps/dhcpserver/dhcpserver_options.h
|
||||
components/lwip/include/apps/esp_ping.h
|
||||
components/lwip/include/apps/ping/ping.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user