add event SYSTEM_EVENT_AP_STAIPASSIGNED

This commit is contained in:
zhangyanjiao
2018-04-09 11:01:44 +08:00
committed by Liu Zhi Fu
parent 7cc3b648f4
commit 3f031cdd9d
6 changed files with 38 additions and 1 deletions

View File

@@ -334,6 +334,10 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
MAC2STR(stadisconnected->mac), stadisconnected->aid); MAC2STR(stadisconnected->mac), stadisconnected->aid);
break; break;
} }
case SYSTEM_EVENT_AP_STAIPASSIGNED: {
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STAIPASSIGNED");
break;
}
case SYSTEM_EVENT_AP_PROBEREQRECVED: { case SYSTEM_EVENT_AP_PROBEREQRECVED: {
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved; system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved;
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \ ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \

View File

@@ -44,6 +44,7 @@ typedef enum {
SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */ SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */ SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */ SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */ SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */ SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */ SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */

View File

@@ -95,6 +95,7 @@ static dhcps_lease_t dhcps_poll;
static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
static dhcps_offer_t dhcps_offer = 0xFF; static dhcps_offer_t dhcps_offer = 0xFF;
static dhcps_offer_t dhcps_dns = 0x00; static dhcps_offer_t dhcps_dns = 0x00;
static dhcps_cb_t dhcps_cb;
/****************************************************************************** /******************************************************************************
* FunctionName : dhcps_option_info * FunctionName : dhcps_option_info
@@ -679,6 +680,10 @@ static void send_ack(struct dhcps_msg *m, u16_t len)
DHCPS_LOG("dhcps: send_ack>>udp_sendto result %x\n", SendAck_err_t); DHCPS_LOG("dhcps: send_ack>>udp_sendto result %x\n", SendAck_err_t);
#endif #endif
if (SendAck_err_t == ERR_OK) {
dhcps_cb(m->yiaddr);
}
if (p->ref != 0) { if (p->ref != 0) {
#if DHCPS_DEBUG #if DHCPS_DEBUG
DHCPS_LOG("udhcp: send_ack>>free pbuf\n"); DHCPS_LOG("udhcp: send_ack>>free pbuf\n");
@@ -1105,6 +1110,19 @@ static void dhcps_poll_set(u32_t ip)
} }
/******************************************************************************
* FunctionName : dhcps_set_new_lease_cb
* Description : set callback for dhcp server when it assign an IP
* to the connected dhcp client
* Parameters : cb -- callback for dhcp server
* Returns : none
*******************************************************************************/
void dhcps_set_new_lease_cb(dhcps_cb_t cb)
{
dhcps_cb = cb;
}
/****************************************************************************** /******************************************************************************
* FunctionName : dhcps_start * FunctionName : dhcps_start
* Description : start dhcp server function * Description : start dhcp server function

View File

@@ -70,6 +70,8 @@ typedef struct {
dhcps_lease_t dhcps_poll; dhcps_lease_t dhcps_poll;
} dhcps_options_t; } dhcps_options_t;
typedef void (*dhcps_cb_t)(u8_t client_ip[4]);
static inline bool dhcps_router_enabled (dhcps_offer_t offer) static inline bool dhcps_router_enabled (dhcps_offer_t offer)
{ {
return (offer & OFFER_ROUTER) != 0; return (offer & OFFER_ROUTER) != 0;
@@ -87,6 +89,7 @@ void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip); bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
void dhcps_dns_setserver(const ip_addr_t *dnsserver); void dhcps_dns_setserver(const ip_addr_t *dnsserver);
ip4_addr_t dhcps_dns_getserver(); ip4_addr_t dhcps_dns_getserver();
void dhcps_set_new_lease_cb(dhcps_cb_t cb);
#endif #endif

View File

@@ -85,6 +85,15 @@ static void tcpip_adapter_api_cb(void* api_msg)
return; return;
} }
static void tcpip_adapter_dhcps_cb(u8_t client_ip[4])
{
ESP_LOGI(TAG,"softAP assign IP to station,IP is: %d.%d.%d.%d",
client_ip[0],client_ip[1],client_ip[2],client_ip[3]);
system_event_t evt;
evt.event_id = SYSTEM_EVENT_AP_STAIPASSIGNED;
esp_event_send(&evt);
}
void tcpip_adapter_init(void) void tcpip_adapter_init(void)
{ {
int ret; int ret;
@@ -181,6 +190,8 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
netif_set_up(esp_netif[tcpip_if]); netif_set_up(esp_netif[tcpip_if]);
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) { if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
dhcps_set_new_lease_cb(tcpip_adapter_dhcps_cb);
dhcps_start(esp_netif[tcpip_if], ip_info->ip); dhcps_start(esp_netif[tcpip_if], ip_info->ip);
ESP_LOGD(TAG, "dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")", ESP_LOGD(TAG, "dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")",