فهرست منبع

lwip: Add client's MAC addr to dhcp server cb

* Extended storage for staipassigned events to pass client's MAC address.
* Added client's MAC to dhcp server callback
* Posting the staipassigned events with clients IP and MAC address
David Cermak 4 سال پیش
والد
کامیت
e3d71c984a

+ 2 - 1
components/esp_netif/include/esp_netif_types.h

@@ -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;
 
 

+ 7 - 7
components/esp_netif/lwip/esp_netif_lwip.c

@@ -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);

+ 6 - 14
components/lwip/apps/dhcpserver/dhcpserver.c

@@ -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) {

+ 6 - 14
components/lwip/include/apps/dhcpserver/dhcpserver.h

@@ -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__
 
@@ -74,7 +66,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)
 {

+ 0 - 2
tools/ci/check_copyright_ignore.txt

@@ -1224,11 +1224,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