Exemple #1
0
int sj_wifi_connect() {
  int ret;
  SlSecParams_t sp;

  if (!ensure_role_sta()) return 0;

  if (s_wifi_sta_config.static_ip.ipV4 != 0) {
    ret = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,
                       IPCONFIG_MODE_ENABLE_IPV4,
                       sizeof(s_wifi_sta_config.static_ip),
                       (unsigned char *) &s_wifi_sta_config.static_ip);
  } else {
    _u8 val = 1;
    ret = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,
                       IPCONFIG_MODE_ENABLE_IPV4, sizeof(val), &val);
  }
  if (ret != 0) return 0;

  /* Turning the device off and on for the role change to take effect. */
  if (!restart_nwp()) return 0;

  sp.Key = (_i8 *) s_wifi_sta_config.pass;
  sp.KeyLen = strlen(s_wifi_sta_config.pass);
  sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;

  ret = sl_WlanConnect((const _i8 *) s_wifi_sta_config.ssid,
                       strlen(s_wifi_sta_config.ssid), 0, &sp, 0);
  if (ret != 0) return 0;

  LOG(LL_INFO, ("Connecting to %s", s_wifi_sta_config.ssid));

  return 1;
}
Exemple #2
0
int sj_wifi_scan(sj_wifi_scan_cb_t cb) {
  const char *ssids[21];
  Sl_WlanNetworkEntry_t info[20];

  if (!ensure_role_sta()) return 0;

  int n = sl_WlanGetNetworkList(0, 20, info);
  if (n < 0) return 0;
  int i;
  for (i = 0; i < n; i++) {
    ssids[i] = (char *) info[i].ssid;
  }
  ssids[i] = NULL;
  cb(s_v7, ssids);
  return 1;
}
Exemple #3
0
void miot_wifi_scan(miot_wifi_scan_cb_t cb, void *arg) {
  const char *ssids[21];
  const char **res = NULL;
  int i, n;
  Sl_WlanNetworkEntry_t info[20];

  if (!ensure_role_sta()) goto out;

  n = sl_WlanGetNetworkList(0, 20, info);
  if (n < 0) goto out;
  for (i = 0; i < n; i++) {
    ssids[i] = (char *) info[i].ssid;
  }
  ssids[i] = NULL;
  res = ssids;
out:
  cb(res, arg);
}