/**
 * @brief Scans area for access points. Blocks operation to allow for scan.
 *
 * To scan for APs, first call scanAccessPoints() with an appropriate scan time
 * (recommended scan_time = 4000ms). Create an AccessPointInfo struct and pass
 * that to getNextAccessPoint(). Continue to call getNextAccessPoint() until it
 * returns false (there are no more APs to scan).
 *
 * @param[in] scan_time time to scan networks in milliseconds
 * @return True if scan succeeded. False otherwise.
 */
bool SFE_CC3000::scanAccessPoints(unsigned int scan_time)
{
    int i;
    unsigned long channel_timeouts[SCAN_NUM_CHANNELS];
    
    /* If CC3000 is not initialized, return false. */
	if (!getInitStatus()) {
        return false;
    }
    
    /* Create channel interval list for AP scanning */
    for (i = 0; i < SCAN_NUM_CHANNELS; i++) {
        channel_timeouts[0] = SCAN_CHANNEL_TIMEOUT;
    }
    
    /* Setup access point scan */
    if (wlan_ioctl_set_scan_params( scan_time, 
                                    SCAN_MIN_DWELL_TIME,
                                    SCAN_MAX_DWELL_TIME,
                                    SCAN_NUM_PROBE_REQS,
                                    SCAN_CHANNEL_MASK,
                                    SCAN_RSSI_THRESHOLD,
                                    SCAN_NSR_THRESHOLD,
                                    SCAN_DEFAULT_TX_POWER,
                                    channel_timeouts ) != CC3000_SUCCESS) {
        return false;
    }

    /* Wait for scan to complete */
    delay(scan_time + 500);
    
    /* Re-initialize AP counters */
    num_access_points_ = 0;
    access_point_count_ = 0;
    
    /* Get first scan result in order to obtain the total number of APs */
    if (wlan_ioctl_get_scan_results(0, (unsigned char *)&ap_scan_result_) != 
                                                            CC3000_SUCCESS ){
        return false;
    }
    num_access_points_ = ap_scan_result_.num_networks;
    
    /* Stop scan */
    if (wlan_ioctl_set_scan_params( 0, 
                                    SCAN_MIN_DWELL_TIME,
                                    SCAN_MAX_DWELL_TIME,
                                    SCAN_NUM_PROBE_REQS,
                                    SCAN_CHANNEL_MASK,
                                    SCAN_RSSI_THRESHOLD,
                                    SCAN_NSR_THRESHOLD,
                                    SCAN_DEFAULT_TX_POWER,
                                    channel_timeouts ) != CC3000_SUCCESS) {
        return false;
    }

    return true;
}
bool Adafruit_CC3000::scanSSIDs(uint32_t time)
{
  const unsigned long intervalTime[16] = { 2000, 2000, 2000, 2000,  2000,
    2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 };

  if (!_initialised)
  {
    return false;
  }

  // We can abort a scan with a time of 0
  if (time)
  {
    CHECK_PRINTER {
      CC3KPrinter->println(F("Started AP/SSID scan\n\r"));
    }
  }

  // Set  SSID Scan params to includes channels above 11 
  CHECK_SUCCESS(
      wlan_ioctl_set_scan_params(time, 20, 100, 5, 0x1FFF, -120, 0, 300,
          (unsigned long * ) &intervalTime),
          "Failed setting params for SSID scan", false);

  return true;
}
Esempio n. 3
0
int WifiScan::startScan() {
   const unsigned long intervalTime[16] = { 2000, 2000, 2000, 2000,  2000,
        2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 };

    wlan_ioctl_set_scan_params(4000, 20, 100, 5, 0x7FF, -120, 0, 300, 
        (unsigned long * ) &intervalTime);

    return 0;
}
Esempio n. 4
0
void hw_net_initialize (void)
{
	CC3000_START;
	SpiInit(4e6);
	hw_wait_us(10);

	wlan_init(CC3000_UsynchCallback, NULL, NULL, NULL, ReadWlanInterruptPin,
	WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);

	wlan_start(0);

	int r = wlan_ioctl_set_connection_policy(0, 0, 0);
	if (r != 0) {
		TM_DEBUG("Fail setting policy %i", r);
	}

	r = wlan_ioctl_set_scan_params(10000, 100, 100, 5, 0x7FF, -100, 0, 205, wifi_intervals);
	if (r != 0) {
		TM_DEBUG("Fail setting scan params %i", r);
	}

	r = wlan_ioctl_set_connection_policy(0, true, true);
	if (r != 0) {
		TM_DEBUG("Fail setting connection policy %i", r);
	}

	wlan_stop();
	hw_wait_ms(10);
	wlan_start(0);

//	tm_sleep_ms(100);
//	TM_COMMAND('w',"setting event mask\n");
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);
//	TM_COMMAND('w',"done setting event mask\n");

 	unsigned long aucDHCP = 14400;
	unsigned long aucARP = 3600;
	unsigned long aucKeepalive = 10;
	unsigned long aucInactivity = 0;
	if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) {
		TM_DEBUG("Error setting inactivity timeout!");
	}

	unsigned char version[2];
	if (nvmem_read_sp_version(version)) {
		TM_ERR("Failed to read CC3000 firmware version.");
	} 

	memcpy(hw_cc_ver, version, 2);

	CC3000_END;
}
Esempio n. 5
0
void loop() {

    netapp_ipconfig(&ipconfig);
    char connectedSSID[32];
    sprintf(connectedSSID, "%s", ipconfig.uaSSID);



    digitalWrite(ledPin1,HIGH);
    delay(50);
    digitalWrite(ledPin1,LOW);
    delay(50);

    long errParams = wlan_ioctl_set_scan_params(1000, 20, 30, 2, 0x7ff, -80, 0, 205, aiIntervalList[16]);
    long errResults = wlan_ioctl_get_scan_results(0, ucResults);
    int _numEntry = ((uint8_t) ucResults[3] << 24) | ((uint8_t) ucResults[2] << 16) | ((uint8_t) ucResults[1] << 8) | ((uint8_t) ucResults[0]);

    if (errParams == 0 && errResults == 0 && _numEntry > 0) {


        digitalWrite(ledPin2,HIGH);
        delay(50);
        digitalWrite(ledPin2,LOW);

    	int _stat = ((uint8_t) ucResults[7] << 24) | ((uint8_t) ucResults[6] << 16) | ((uint8_t) ucResults[5] << 8) | ((uint8_t) ucResults[4]);
    	bool _valid = (uint8_t) ucResults[8]  & 0x1;
    	int _rssi = (uint8_t) ucResults[8] >> 1;
    	int _mode = ((uint8_t) ucResults[9] | 0xC0) & 0x3;
    	int _ssidlen = (uint8_t) ucResults[9] >> 2;

    	char ssid[32];
    	int idx = 0;
    	while(strcmp(connectedSSID, ssid) != 0) {
    		ssid[idx] = ucResults[idx+12];
    		idx++;
        	ssid[_ssidlen] = (char) NULL;
    	}

        digitalWrite(ledPin3,HIGH);
        delay(100);
        digitalWrite(ledPin3,LOW);


        Serial.print("WiFi scan status: ");
    	switch (_stat) {
    		case 0:
    			Serial.print("aged, ");
    			break;
    		case 1:
    			Serial.print("valid, ");
    			break;
    		case 2:
    			Serial.print("no results, ");
    			break;
    	}

    	Serial.print(_numEntry);
    	Serial.print(" nets found. ");
    	Serial.print(ssid);
        Serial1.println(ssid);

        if (_valid){
    		Serial.print(" is valid, RSSI: ");
        }
    	else
    		Serial.print("not valid, RSSI: ");

        Serial.print(_rssi);
        Serial1.println(_rssi);

    	Serial.print(", mode: ");
    	switch (_mode) {
    		case 0:
    			Serial.println("OPEN");
    			break;
    		case 1:
    			Serial.println("WEP");
    			break;
    		case 2:
    			Serial.println("WPA");
    			break;
    		case 3:
    			Serial.println("WPA2");
    			break;
    	}



        // else {
        //     Serial.print(connectedSSID);
        //     Serial.print(" >______< ");
        //     Serial.println(ssid);
        // }

        incomingByte = Serial.read();
        //key press 'a' to get data
        if (incomingByte == 97){
            Serial.println(Network.localIP());
            Serial.println(Network.subnetMask());
            Serial.println(Network.gatewayIP());
            Serial.println(Network.SSID());
        }


    }
Esempio n. 6
0
void ListAccessPoints(void)
{
  unsigned long aiIntervalList[NUM_CHANNELS];
  uint8_t rval;
  scanResults sr;
  int apCounter, i;
  char localB[33];

  if (!isInitialized)
    {
      printf("CC3000 not initialized; can't list access points.\n");
      return;
    }

  printf("List visible access points\n");

  printf("  Setting scan parameters...\n");

  for (i=0; i<NUM_CHANNELS; i++)
    {
      aiIntervalList[i] = 2000;
    }

  rval = wlan_ioctl_set_scan_params(
      1000,           /* Enable start application scan */
      100,            /* Minimum dwell time on each channel */
      100,            /* Maximum dwell time on each channel */
      5,              /* Number of probe requests */
      0x7ff,          /* Channel mask */
      -80,            /* RSSI threshold */
      0,              /* SNR threshold */
      205,            /* Probe TX power */
      aiIntervalList  /* Table of scan intervals per channel */
      );

  if (rval!=0)
    {
      printf("  Got back unusual result from wlan_ioctl_set_scan_params, can't continue: %d\n", rval);
      return;
    }

#if 0
  printf("  Sleeping 5 seconds to let the CC3000 discover APs...\n");
  usleep(5000000);
#endif

  printf("  Getting AP count...\n");

  /* On the first call to get_scan_results, sr.numNetworksFound will return the
   * actual # of APs currently seen. Get that # then loop through and print
   * out what's found.
   */

  if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr))!=0)
    {
      printf("  Got back unusual result from wlan_ioctl_get scan results, can't continue: %d\n", rval);
      return;
    }

  apCounter = sr.numNetworksFound;
  printf("  Number of APs found: %d\n", apCounter);

  do
    {
      if (sr.isValid)
        {
          printf("    ");
          switch (sr.securityMode)
            {
            case WLAN_SEC_UNSEC:  /* 0 */
              printf("OPEN ");
              break;
            case WLAN_SEC_WEP:    /* 1 */
              printf("WEP  ");
              break;
            case WLAN_SEC_WPA:    /* 2 */
              printf("WPA  ");
              break;
            case WLAN_SEC_WPA2:   /* 3 */
              printf("WPA2 ");
              break;
            }

          sprintf(localB, "%3u  ", sr.rssi);
          printf("%s", localB);
          memset(localB, 0, 33);
          memcpy(localB, sr.ssid_name, sr.ssidLength);
          printf("%s\n", localB);
        }

      if (--apCounter>0)
        {
          if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr)) !=0)
            {
              printf("  Got back unusual result from wlan_ioctl_get scan, can't continue: %d\n", rval);
              return;
            }
        }
    }
  while (apCounter>0);

  printf("  Access Point list finished.\n");
}