mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-28 20:58:31 +00:00
Fix AP configuration on CC3200
Factor out MG task for clarity and ease of reuse. PUBLISHED_FROM=18f1aedd3c227b43a49f59a67076905917dd6cab
This commit is contained in:
1 parent
8296e0f485
commit
5e31914dc1
5 files changed
+122
-39
No files matched your search
+33
-3
@@ -23,20 +23,28 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *e) {
|
||||
}
|
||||
}
|
||||
|
||||
int ip_acquired = 0;
|
||||
|
||||
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *e) {
|
||||
if (e->Event == SL_NETAPP_IPV4_IPACQUIRED_EVENT) {
|
||||
SlIpV4AcquiredAsync_t *ed = &e->EventData.ipAcquiredV4;
|
||||
LOG(LL_INFO, ("IP: %lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
|
||||
LOG(LL_INFO, ("IP acquired: %lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
|
||||
SL_IPV4_BYTE(ed->ip, 2), SL_IPV4_BYTE(ed->ip, 1),
|
||||
SL_IPV4_BYTE(ed->ip, 0)));
|
||||
GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
|
||||
ip_acquired = 1;
|
||||
} else if (e->Event == SL_NETAPP_IP_LEASED_EVENT) {
|
||||
LOG(LL_INFO, ("IP leased"));
|
||||
} else {
|
||||
LOG(LL_INFO, ("NetApp event %d", e->Event));
|
||||
}
|
||||
}
|
||||
|
||||
bool wifi_setup_ap(const char *ssid, const char *pass, int channel) {
|
||||
uint8_t v;
|
||||
LOG(LL_INFO, ("WiFi: configuring AP %s", ssid));
|
||||
sl_WlanSetMode(ROLE_AP);
|
||||
if (sl_WlanSetMode(ROLE_AP) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(ssid),
|
||||
(const uint8_t *) ssid) != 0) {
|
||||
return false;
|
||||
@@ -54,18 +62,40 @@ bool wifi_setup_ap(const char *ssid, const char *pass, int channel) {
|
||||
if (sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, &v) != 0) {
|
||||
return false;
|
||||
}
|
||||
sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID);
|
||||
{
|
||||
SlNetCfgIpV4Args_t ipcfg;
|
||||
memset(&ipcfg, 0, sizeof(ipcfg));
|
||||
if (!inet_pton(AF_INET, "192.168.4.1", &ipcfg.ipV4) ||
|
||||
!inet_pton(AF_INET, "255.255.255.0", &ipcfg.ipV4Mask) ||
|
||||
/* This means "disable". 0.0.0.0 won't do. */
|
||||
!inet_pton(AF_INET, "255.255.255.255", &ipcfg.ipV4DnsServer) ||
|
||||
/* We'd like to disable gateway too, but DHCP server refuses to start.
|
||||
*/
|
||||
!inet_pton(AF_INET, "192.168.4.1", &ipcfg.ipV4Gateway) ||
|
||||
sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE, IPCONFIG_MODE_ENABLE_IPV4,
|
||||
sizeof(ipcfg), (uint8_t *) &ipcfg) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
{
|
||||
SlNetAppDhcpServerBasicOpt_t dhcpcfg;
|
||||
memset(&dhcpcfg, 0, sizeof(dhcpcfg));
|
||||
dhcpcfg.lease_time = 900;
|
||||
if (!inet_pton(AF_INET, "192.168.4.20", &dhcpcfg.ipv4_addr_start) ||
|
||||
!inet_pton(AF_INET, "192.168.4.200", &dhcpcfg.ipv4_addr_last) ||
|
||||
sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT,
|
||||
sizeof(dhcpcfg), (uint8_t *) &dhcpcfg) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sl_Stop(0);
|
||||
sl_Start(NULL, NULL, NULL);
|
||||
if (sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID) != 0) {
|
||||
LOG(LL_ERROR, ("DHCP server failed to start"));
|
||||
return false;
|
||||
}
|
||||
LOG(LL_INFO, ("WiFi: AP %s configured", ssid));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user