]> granicus.if.org Git - esp-idf/blob - components/esp_wifi/src/mesh_event.c
f0b90ae4228b0a81c72a653b8871d68ee5733676
[esp-idf] / components / esp_wifi / src / mesh_event.c
1 // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string.h>
16 #include "esp_event.h"
17 #include "esp_mesh.h"
18
19 /* mesh event callback handler */
20 mesh_event_cb_t g_mesh_event_cb = NULL;
21
22 esp_err_t esp_event_mesh_hook(system_event_t *event)
23 {
24     if (event->event_id == SYSTEM_EVENT_STA_GOT_IP || event->event_id == SYSTEM_EVENT_STA_LOST_IP) {
25         if (g_mesh_event_cb) {
26             mesh_event_t mevent;
27             if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
28                 mevent.id = MESH_EVENT_ROOT_GOT_IP;
29                 memcpy(&mevent.info.got_ip, &event->event_info.got_ip, sizeof(system_event_sta_got_ip_t));
30             } else {
31                 mevent.id = MESH_EVENT_ROOT_LOST_IP;
32             }
33             g_mesh_event_cb(mevent);
34         }
35     }
36     return ESP_OK;
37 }