Exemplo n.º 1
0
uint8_t *WiFiClass::macAddress(uint8_t *mac)
{
	m2m_wifi_get_mac_address(mac);
	byte tmpMac[6], i;
	
	m2m_wifi_get_mac_address(tmpMac);
	
	for(i = 0; i < 6; i++)
		mac[i] = tmpMac[5-i];
		
	return mac;
}
Exemplo n.º 2
0
tenuWifiMode localParseEventLoop(ParseClientInternal *parseClient)
{
	tenuWifiMode wifiStatus = M2M_WIFI_MODE_UNKNOWN;

	while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) {
	}

#ifdef ENABLE_MDNS
	if(gTimerCbMdns == 1)
	{
		gTimerCbMdns = 0;
		printf("Send mDNS====\r\n");
		mdnsd_send_response();
	}
#endif

	switch (gParseMode)
	{
		case M2M_WIFI_MODE_UNKNOWN:
			break;

		case M2M_WIFI_MODE_AP_ENABLE:
		{
			uint8 macAddr[6] = {0,};
			uint8_t macInfo[2] = {0,};

			m2m_wifi_get_mac_address(macAddr);
			macInfo[0] = macAddr[4];
			macInfo[1] = macAddr[5];

			deviceConfigAddKey( 0, "applicationId", "App ID", NULL );
			deviceConfigAddKey( 0, "clientKey", "Client Key", NULL );
			deviceConfigAddKey( 0, "installationId", "Installation ID", NULL );
			deviceConfigAddKey( 0, "sessionToken", "Session Token", NULL );
			deviceConfigAddKey( 0, "deviceName", "Device Name", NULL );

			/* AP Mode : Enable*/
			fluffy_wifi_ap_mode(1, macInfo);
			gParseMode = M2M_WIFI_MODE_AP_PROV;

			wifiStatus = M2M_WIFI_MODE_AP_PROV;
			break;
		}

		case M2M_WIFI_MODE_AP_PROV:
		{
			/* Provision AP or HTTP */
			fluffy_trans_ap_provision();
			gParseMode = M2M_WIFI_MODE_AP;

			wifiStatus = M2M_WIFI_MODE_AP;
			break;
		}

		case M2M_WIFI_MODE_AP:
		{
			if (fluffy_get_ap_mode_completed())
			{
				printf("WIFI : Complete AP Provision\r\n");

				nm_bsp_sleep(DELAY_FOR_MODE_CHANGE);

				/* AP Mode : Disable*/
				fluffy_trans_socket_close();
				fluffy_wifi_ap_mode(0, NULL);
				nm_bsp_sleep(DELAY_FOR_MODE_CHANGE);
				gParseMode = M2M_WIFI_MODE_STA_ENABLE;

				wifiStatus = M2M_WIFI_MODE_STA_ENABLE;
			}

			break;
		}

		// AP mode for provisioning
		////////////////////////////////////////////////////////
		// Station mode for connecting parse server (request & push)

		case M2M_WIFI_MODE_STA_ENABLE:
		{
/*
printf( "applicationId = %s\r\n", deviceConfigGetValue( 0, "applicationId" ) );
printf( "clientKey = %s\r\n", deviceConfigGetValue( 0, "clientKey" ) );
printf( "installationId = %s\r\n", deviceConfigGetValue( 0, "installationId" ) );
printf( "deviceId = %s\r\n", deviceConfigGetValue( 0, "sessionToken" ) );
printf( "name = %s\r\n", deviceConfigGetValue( 0, "deviceName" ) );
*/

			/* Station Mode : Enable */
			fluffy_wifi_stat_mode(1);
			gParseMode = M2M_WIFI_MODE_STA_CON;

			wifiStatus = M2M_WIFI_MODE_STA_CON;
			break;
		}

		case M2M_WIFI_MODE_STA_CON:
		{
			if (fluffy_get_wifi_connected())
			{
#ifdef ENABLE_MDNS
				if ( !mdnsd_start( deviceConfigGetValue( 0, "deviceName" ) ) )
				{
					printf("Error, mDNS Start\r\n");
				}

				tcc_enable_callback(&tempTccModule, TCC_CALLBACK_CHANNEL_3);
#endif

				gParseMode = M2M_WIFI_MODE_STA;

				wifiStatus = M2M_WIFI_MODE_STA;
			}

			break;
		}

		case M2M_WIFI_MODE_STA:
		{
			if( parseClient && parseClient->isStartPushService )
			{
				parseClient->isStartPushService = 0;
				fluffy_trans_sta_socket();
			}

			wifiStatus = M2M_WIFI_MODE_STA;
			break;
		}

		default:
		{
			printf("Unknown WIFI Mode : %d\r\n", gParseMode);
			wifiStatus = gParseMode;
			break;
		}
	}

	return wifiStatus;
}
Exemplo n.º 3
0
error_t wilc1000Init(NetInterface *interface)
{
   int8_t status;
   tstrWifiInitParam param;

   //STA or AP mode?
   if(interface->nicDriver == &wilc1000StaDriver)
   {
      //Debug message
      TRACE_INFO("Initializing WILC1000 (STA mode)...\r\n");
   }
   else
   {
      //Debug message
      TRACE_INFO("Initializing WILC1000 (AP mode)...\r\n");
   }

   //Start of exception handling block
   do
   {
      //Initialization sequence is performed once at startup
      if(wilc1000StaInterface == NULL && wilc1000ApInterface == NULL)
      {
         //Low-level initialization
         status = nm_bsp_init();

         //Check status code
         if(status != M2M_SUCCESS)
            break;

         //Set default parameters
         memset(&param, 0, sizeof(param));

         //Register callback functions
         param.pfAppWifiCb = wilc1000AppWifiEvent;
         param.pfAppMonCb = NULL;
         param.strEthInitParam.pfAppWifiCb = NULL;
         param.strEthInitParam.pfAppEthCb = wilc1000AppEthEvent;

         //Set receive buffer
         param.strEthInitParam.au8ethRcvBuf = rxBuffer;
         param.strEthInitParam.u16ethRcvBufSize = WILC1000_RX_BUFFER_SIZE - ETH_CRC_SIZE;

         //Initialize WILC1000 controller
         status = m2m_wifi_init(&param);

         //Check status code
         if(status != M2M_SUCCESS)
            break;

         //Optionally set the station MAC address
         if(macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR))
         {
            //Use the factory preprogrammed station address
            status = m2m_wifi_get_mac_address(interface->macAddr.b);

            //Check status code
            if(status != M2M_SUCCESS)
               break;

            //Generate the 64-bit interface identifier
            macAddrToEui64(&interface->macAddr, &interface->eui64);
         }
         else
         {
            //Override the factory preprogrammed address
            status = m2m_wifi_set_mac_address(interface->macAddr.b);

            //Check status code
            if(status != M2M_SUCCESS)
               break;
         }
      }
      else
      {
         //Initialization was already done
         status = M2M_SUCCESS;
      }

      //STA or AP mode?
      if(interface->nicDriver == &wilc1000StaDriver)
      {
         //Save underlying network interface (STA mode)
         wilc1000StaInterface = interface;

         if(wilc1000ApInterface != NULL)
         {
            wilc1000StaInterface->macAddr = wilc1000ApInterface->macAddr;
            wilc1000StaInterface->eui64 = wilc1000ApInterface->eui64;
         }
      }
      else
      {
         //Save underlying network interface (AP mode)
         wilc1000ApInterface = interface;

         if(wilc1000StaInterface != NULL)
         {
            wilc1000ApInterface->macAddr = wilc1000StaInterface->macAddr;
            wilc1000ApInterface->eui64 = wilc1000StaInterface->eui64;
         }
      }

      //End of exception handling block
   } while(0);

   //WILC1000 is now ready to send
   osSetEvent(&interface->nicTxEvent);

   //Return status code
   if(status == M2M_SUCCESS)
      return NO_ERROR;
   else
      return ERROR_FAILURE;
}