123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
-
- #include <unistd.h>
- #include "lwip/ip_addr.h"
- #include "lwip/netifapi.h"
- #include "wifi_hotspot.h"
- #include "wifi_hotspot_config.h"
- #include "iot_softap.h"
- #include "iot_demo_def.h"
- #define DEFAULT_AP_NAME "TestIotAP"
- static struct netif *g_netif = NULL;
- static void SetAddr(struct netif *pst_lwip_netif)
- {
- ip4_addr_t st_gw;
- ip4_addr_t st_ipaddr;
- ip4_addr_t st_netmask;
- IP4_ADDR(&st_ipaddr, 192, 168, 10, 1);
- IP4_ADDR(&st_gw, 192, 168, 10, 1);
- IP4_ADDR(&st_netmask, 255, 255, 255, 0);
- netifapi_netif_set_addr(pst_lwip_netif, &st_ipaddr, &st_netmask, &st_gw);
- }
- static void ResetAddr(struct netif *pst_lwip_netif)
- {
- ip4_addr_t st_gw;
- ip4_addr_t st_ipaddr;
- ip4_addr_t st_netmask;
- IP4_ADDR(&st_ipaddr, 0, 0, 0, 0);
- IP4_ADDR(&st_gw, 0, 0, 0, 0);
- IP4_ADDR(&st_netmask, 0, 0, 0, 0);
- netifapi_netif_set_addr(pst_lwip_netif, &st_ipaddr, &st_netmask, &st_gw);
- }
- int BOARD_SoftApStart(const char *ap_name)
- {
- HotspotConfig config = {0};
- ip4_addr_t st_gw;
- ip4_addr_t st_ipaddr;
- ip4_addr_t st_netmask;
- char *apName = ap_name;
- char ifname[BUFF_SIZE] = {0};
- int retval;
- if (IsHotspotActive() == WIFI_HOTSPOT_ACTIVE) {
- RaiseLog(LOG_LEVEL_ERR, "WIFI_HOTSPOT_ACTIVE \n");
- return -1;
- }
- if (apName == NULL) {
- apName = DEFAULT_AP_NAME;
- }
- if (strcpy_s(config.ssid, sizeof(config.ssid), apName) != 0) {
- RaiseLog(LOG_LEVEL_ERR, "[sample] strcpy ssid fail.\n");
- return -1;
- }
- config.securityType = WIFI_SEC_TYPE_OPEN;
- retval = SetHotspotConfig((const HotspotConfig *)(&config));
- if (retval != WIFI_SUCCESS) {
- RaiseLog(LOG_LEVEL_ERR, "SetHotspotConfig \n");
- return -1;
- }
- retval = EnableHotspot();
- if (retval != WIFI_SUCCESS) {
- RaiseLog(LOG_LEVEL_ERR, "EnableHotspot failed! \n");
- return -1;
- }
- g_netif = netifapi_netif_find("ap0");
- if (g_netif != NULL) {
- SetAddr(g_netif);
- dhcps_start(g_netif, NULL, 0);
- }
- return 0;
- }
- void BOARD_SoftApStop(void)
- {
- if (IsHotspotActive() == WIFI_HOTSPOT_NOT_ACTIVE) {
- RaiseLog(LOG_LEVEL_ERR, "WIFI_HOTSPOT_NOT_ACTIVE \n");
- return;
- }
- DisableHotspot();
- if (g_netif) {
- ResetAddr(g_netif);
- }
- }
|