Beispiel #1
0
uint8_t wifi_set_profile( char* ssid, char* password, uint8_t encrypt_mode){
    uint8_t pairwise_cipher_or_key_len, group_cipher, key_management, key_len;
    uint8_t* key;
    
    switch(encrypt_mode){
        case WLAN_SEC_UNSEC://None
            pairwise_cipher_or_key_len = 0;
            group_cipher = 0;
            key_management = 0;
            key = NULL;
            key_len = 0;
            break;
        case WLAN_SEC_WEP://WEP
            pairwise_cipher_or_key_len = strlen(password);
            group_cipher = 0;
            key_management = 1; // TODO the various posts about it diverge on this value. Some say it should be 1 (http://e2e.ti.com/support/low_power_rf/f/851/t/311630.aspx), driver code uses 0...
            key = (uint8_t*)password;
            key_len = 0;
            break;
        case WLAN_SEC_WPA://WPA
        case WLAN_SEC_WPA2://WPA2
            pairwise_cipher_or_key_len = 0x18;
            group_cipher = 0x1e;
            key_management = 2;
            key = (uint8_t*)password;
            key_len = strlen(password);
            break;
        default:
            DWIFI_ERR_PRINTF("ERR encrypt mode=%u\r\n",encrypt_mode);
            return 2;
            break;
    }

    // delete all profiles
    CC3000_WIFI_CHECK_SUCCESS( wlan_ioctl_del_profile(255), "ERR del prof.", 1);
    DWIFI_INFO_PRINTLN("del prof");

    // write profile
    CC3000_WIFI_CHECK_SUCCESS(
        wlan_add_profile(
            encrypt_mode,                   // security type
            (uint8_t*)ssid,                 // SSID
            strlen(ssid),                   // SSID length
            NULL, 							// BSSID (currently unsupported it seems)
            1,								// Priority
            pairwise_cipher_or_key_len,		// PairwiseCipher
            group_cipher, 					// GroupCipher
            key_management,					// KEY management
            key,				            // KEY
            key_len),                       // KEY length
        "ERR prof",
        2);
    DWIFI_INFO_PRINTLN("prof added");
    
    //set policy to use profiles and fast reconnect
    CC3000_WIFI_CHECK_SUCCESS( wlan_ioctl_set_connection_policy(0, 1, 1), "ERR connect policy", 3);
    DWIFI_INFO_PRINTLN("connect policy 011");
    return 0;
}
Beispiel #2
0
void ManualAddProfile(void)
{
  char ssidName[] = "YourAP";
  char AP_KEY[] = "yourpass";
  uint8_t rval;

  if (!isInitialized)
    {
      printf("CC3000 not initialized; can't run manual add profile.");
      return;
    }

  printf("Starting manual add profile...\n");

  printf("  Disabling auto connection...\n");
  wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);

  printf("  Adding profile...\n");
  rval = wlan_add_profile  (
          WLAN_SEC_WPA2,     /* WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 */
          (uint8_t *)ssidName,
          strlen(ssidName),
          NULL,              /* BSSID, TI always uses NULL */
          0,                 /* Profile priority */
          0x18,              /* Key length for WEP security, undocumented why this needs to be 0x18 */
          0x1e,              /* Key index, undocumented why this needs to be 0x1e */
          0x2,               /* key management, undocumented why this needs to be 2 */
          (uint8_t *)AP_KEY, /* WPA security key */
          strlen(AP_KEY)     /* WPA security key length */
          );

  if (rval!=255)
    {
      /* This code is lifted from http://e2e.ti.com/support/low_power_rf/f/851/p/180859/672551.aspx;
       * the actual API documentation on wlan_add_profile doesn't specify any of this....
       */

      printf("  Manual add profile success, stored in profile: %d\n", rval);

      printf("  Enabling auto connection...\n");
      wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);

      printf("  Stopping CC3000...\n");
      wlan_stop();

      printf("  Stopping for 5 seconds...\n");
      usleep(5000000);

      printf("  Restarting CC3000...\n");
      wlan_start(0);

      printf("  Manual add profile done!");
    }
  else
    {
      printf("  Manual add profile failured (all profiles full?).");
    }
}
void wifi_add_profile_callback(const char *ssid,
                               const char *password,
                               unsigned long security_type)
{
  if (0 == password[0]) {
    security_type = WLAN_SEC_UNSEC;
  }

  wlan_profile_index = wlan_add_profile(security_type, (unsigned char *)ssid, strlen(ssid), NULL, 1, 0x18, 0x1e, 2, (unsigned char *)password, strlen(password));

  WLAN_SERIAL_CONFIG_DONE = 1;
}
BOOL cc3000_addProfile(const char* ssid, const char* key, uint8_t secmode) {
  uint32_t ulPriority = 0;

  // taken from wlan.c WPA smart config example
  uint32_t ulPairwiseCipher_Or_TxKeyLen = 0x18;
  uint32_t ulGroupCipher_TxKeyIndex = 0x1e;
  uint32_t ulKeyMgmt = 0x2;

  int32_t result = wlan_add_profile(secmode, (uint8_t*)ssid, strlen(ssid), NULL, ulPriority, ulPairwiseCipher_Or_TxKeyLen, ulGroupCipher_TxKeyIndex, ulKeyMgmt, (uint8_t*)key, strlen(key));
  if (result == -1) {
    printf("failed to add profile %ld\n", result);
    return FALSE;
  }
  return TRUE;
}
Beispiel #5
0
static void cmd_setup_cc3000(BaseSequentialStream *chp, int argc, char *argv[])
{
    char ssid_name[32];
    char ssid_key[40];
    char ssid_sectype[3];
    unsigned long sectype;
    unsigned char rval;

    (void)argv;
    if(argc > 0)
    {
        chprintf(chp, "Usage: smartcfg\r\n");
        return;
    }

    chprintf(chp, "Enter Security profile: \r\n");
    chprintf(chp, "  [0] Unsecured\r\n");
    chprintf(chp, "  [1] WEP\r\n");
    chprintf(chp, "  [2] WPA\r\n");
    chprintf(chp, "  [3] WPA2\r\n");

    shellGetLine(chp, ssid_sectype, 3);
    sectype = ssid_sectype[0] - '0';

    chprintf(chp, "Enter the AP SSID\r\n");
    shellGetLine(chp, ssid_name, 32);

    chprintf(chp, "Enter SSID Key\r\n");
    shellGetLine(chp, ssid_key, 40);

    chprintf(chp, "Type[%d]\r\n", sectype);
    chprintf(chp, "SSID[%s]\r\n", ssid_name);
    chprintf(chp, "Passkey[%s]\r\n", ssid_key);

    chprintf(chp, "Disabling connection policy ...\r\n");
    wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);

    chprintf(chp, "Adding profile ...\r\n");
    rval = wlan_add_profile(sectype,
            (unsigned char *) ssid_name,
            strlen(ssid_name),
            NULL,
            0,
            0x18,
            0x1e,
            0x2,
            (unsigned char *) ssid_key,
            strlen(ssid_key)
            );

    if (rval != 255)
    {
        chprintf(chp, "Add profile returned: %d\r\n", rval);

        chprintf(chp, "Enabling auto connect ...\r\n");
        wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);
        chprintf(chp, "Restarting wlan ...\r\n");
        wlan_stop();
        chThdSleep(MS2ST(500));
        wlan_start(0);

        return;

    }else
    {
        // TODO: Delete profiles and add again
        chprintf(chp, "Error adding profile (list full) ...\r\n");
        return;
    }

    chprintf(chp, "Lan profile added!\r\n");
}
Beispiel #6
0
long
wlan_smart_config_process()
{
    signed long	returnValue;
    unsigned long ssidLen, keyLen;
    unsigned char *decKeyPtr;
    unsigned char *ssidPtr;

    // read the key from EEPROM - fileID 12
    returnValue = aes_read_key(key);

    if (returnValue != 0)
        return returnValue;

    // read the received data from fileID #13 and parse it according to the followings:
    // 1) SSID LEN - not encrypted
    // 2) SSID - not encrypted
    // 3) KEY LEN - not encrypted. always 32 bytes long
    // 4) Security type - not encrypted
    // 5) KEY - encrypted together with true key length as the first byte in KEY
    //	 to elaborate, there are two corner cases:
    //		1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length
    //		2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31
    returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray);

    if (returnValue != 0)
        return returnValue;

    ssidPtr = &profileArray[1];

    ssidLen = profileArray[0];

    decKeyPtr = &profileArray[profileArray[0] + 3];

    aes_decrypt(decKeyPtr, key);
    if (profileArray[profileArray[0] + 1] > 16)
        aes_decrypt((unsigned char *)(decKeyPtr + 16), key);

    if (*(unsigned char *)(decKeyPtr +31) != 0)
    {
        if (*decKeyPtr == 31)
        {
            keyLen = 31;
            decKeyPtr++;
        }
        else
        {
            keyLen = 32;
        }
    }
    else
    {
        keyLen = *decKeyPtr;
        decKeyPtr++;
    }

    // add a profile
    switch (profileArray[profileArray[0] + 2])
    {
    case WLAN_SEC_UNSEC://None
    {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], 	// security type
                                       ssidPtr,		 					// SSID
                                       ssidLen, 							// SSID length
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       0, 0, 0, 0, 0);

        break;
    }

    case WLAN_SEC_WEP://WEP
    {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], 	// security type
                                       ssidPtr, 							// SSID
                                       ssidLen, 							// SSID length
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       keyLen,							// KEY length
                                       0, 								// KEY index
                                       0,
                                       decKeyPtr,						// KEY
                                       0);

        break;
    }

    case WLAN_SEC_WPA://WPA
    case WLAN_SEC_WPA2://WPA2
    {
        returnValue = wlan_add_profile(WLAN_SEC_WPA2, 	// security type
                                       ssidPtr,
                                       ssidLen,
                                       NULL, 							// BSSID
                                       1,								// Priority
                                       0x18,							// PairwiseCipher
                                       0x1e, 							// GroupCipher
                                       2,								// KEY management
                                       decKeyPtr,						// KEY
                                       keyLen);							// KEY length

        break;
    }
    }

    return returnValue;
}
Beispiel #7
0
long wlan_smart_config_process()
{
  signed long  returnValue;
  unsigned long ssidLen, keyLen;
  uint8_t *decKeyPtr;
  uint8_t *ssidPtr;

  /* Read the key from EEPROM - fileID 12 */

  returnValue = aes_read_key(akey);

  if (returnValue != 0)
    {
      return returnValue;
    }

  /* Read the received data from fileID #13 and parse it according to the followings:
   * 1) SSID LEN - not encrypted
   * 2) SSID - not encrypted
   * 3) KEY LEN - not encrypted. always 32 bytes long
   * 4) Security type - not encrypted
   * 5) KEY - encrypted together with true key length as the first byte in KEY
   *   to elaborate, there are two corner cases:
   *   1) the KEY is 32 bytes long. In this case, the first byte does not represent
   *      KEY length
   *   2) the KEY is 31 bytes long. In this case, the first byte represent KEY
   *      length and equals 31
   */

  returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE,
                           0, profileArray);

  if (returnValue != 0)
    {
      return returnValue;
    }

  ssidPtr = &profileArray[1];

  ssidLen = profileArray[0];

  decKeyPtr = &profileArray[profileArray[0] + 3];

  aes_decrypt(decKeyPtr, akey);
  if (profileArray[profileArray[0] + 1] > 16)
    {
      aes_decrypt((uint8_t *)(decKeyPtr + 16), akey);
    }

  if (*(uint8_t *)(decKeyPtr +31) != 0)
    {
      if (*decKeyPtr == 31)
      {
        keyLen = 31;
        decKeyPtr++;
      }
    else
      {
        keyLen = 32;
      }
    }
  else
    {
      keyLen = *decKeyPtr;
      decKeyPtr++;
    }

  /* Add a profile */

  switch (profileArray[profileArray[0] + 2])
    {
    case WLAN_SEC_UNSEC: /* None */
       {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], /* Security type */
                                       ssidPtr,          /* SSID */
                                       ssidLen,          /* SSID length */
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       0, 0, 0, 0, 0);
        break;
       }

    case WLAN_SEC_WEP: /* WEP */
      {
        returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], /* Security type */
                                       ssidPtr,          /* SSID */
                                       ssidLen,          /* SSID length */
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       keyLen,           /* KEY length */
                                       0,                /* KEY index */
                                       0,
                                       decKeyPtr,        /* KEY */
                                       0);
        break;
      }

    case WLAN_SEC_WPA:  /* WPA */
    case WLAN_SEC_WPA2: /* WPA2 */
      {
        returnValue = wlan_add_profile(WLAN_SEC_WPA2,    /* Security type */
                                       ssidPtr,
                                       ssidLen,
                                       NULL,             /* BSSID */
                                       1,                /* Priority */
                                       0x18,             /* PairwiseCipher */
                                       0x1e,             /* GroupCipher */
                                       2,                /* KEY management */
                                       decKeyPtr,        /* KEY */
                                      keyLen);           /* KEY length */
        break;
      }
    }

  return returnValue;
}