/
esp_wifi_port.i
157 lines (125 loc) · 4.02 KB
/
esp_wifi_port.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2018, Erik Moqvist
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This file is part of the Simba project.
*/
#include "simba.h"
#undef BIT
#undef O_RDONLY
#undef O_WRONLY
#undef O_RDWR
#undef O_APPEND
#undef O_CREAT
#undef O_TRUNC
#undef O_EXCL
#undef O_SYNC
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
extern int esp_wifi_station_port_set_connect_status(enum esp_wifi_station_status_t status);
extern int esp_wifi_softap_port_station_connected(void);
extern int esp_wifi_softap_port_station_disconnected(void);
/**
* WiFi event callback.
*/
static esp_err_t event_handler(void *ctx_p, system_event_t *event_p)
{
uint8_t reason;
switch (event_p->event_id) {
case SYSTEM_EVENT_WIFI_READY:
break;
case SYSTEM_EVENT_SCAN_DONE:
break;
case SYSTEM_EVENT_STA_START:
break;
case SYSTEM_EVENT_STA_STOP:
break;
case SYSTEM_EVENT_STA_CONNECTED:
esp_wifi_station_port_set_connect_status(esp_wifi_station_status_connected_t);
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
reason = event_p->event_info.disconnected.reason;
ets_printf("disconnected reason: %d\r\n", reason);
if (reason == WIFI_REASON_NO_AP_FOUND) {
esp_wifi_station_port_set_connect_status(esp_wifi_station_status_no_ap_found_t);
} else if (reason == WIFI_REASON_AUTH_FAIL) {
esp_wifi_station_port_set_connect_status(esp_wifi_station_status_auth_failure_t);
} else {
esp_esp_wifi_connect();
}
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
break;
case SYSTEM_EVENT_STA_GOT_IP:
esp_wifi_station_port_set_connect_status(esp_wifi_station_status_got_ip_t);
break;
case SYSTEM_EVENT_AP_START:
break;
case SYSTEM_EVENT_AP_STOP:
break;
case SYSTEM_EVENT_AP_STACONNECTED:
esp_wifi_softap_port_station_connected();
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
esp_wifi_softap_port_station_disconnected();
break;
case SYSTEM_EVENT_AP_PROBEREQRECVED:
break;
default:
break;
}
return (ESP_OK);
}
static int esp_wifi_port_module_init(void)
{
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
esp_tcpip_adapter_init();
esp_esp_event_loop_init(event_handler, NULL);
esp_esp_wifi_init(&config);
esp_esp_wifi_set_storage(WIFI_STORAGE_RAM);
esp_esp_wifi_start();
return (0);
}
static int esp_wifi_port_set_op_mode(enum esp_wifi_op_mode_t mode)
{
return (esp_esp_wifi_set_mode(mode));
}
static enum esp_wifi_op_mode_t esp_wifi_port_get_op_mode()
{
wifi_mode_t mode;
if (esp_esp_wifi_get_mode(&mode) != ESP_OK) {
return (-1);
}
return (mode);
}
static int esp_wifi_port_set_phy_mode(enum esp_wifi_phy_mode_t mode)
{
return (-1);
}
static enum esp_wifi_phy_mode_t esp_wifi_port_get_phy_mode()
{
return (-1);
}