NETWORK_STATE network_check_set_dhcp( void )
{
	int ready = 0;
	time_t tm;
	SecureSOHO_LAN lan;
	NETWORK_STATE  state = network_get_state();

	switch (state) {
	case NETWORK_STATE_WIRELESS_CONNECTING:
		tm = time(NULL) - network_task.start_time;

		if ( tm >= network_task.timeout ) {
			fprintf(stderr, "Wireless timeout\n");
			stop_wireless_thread();
			network_set_state(NETWORK_STATE_WIRELESS_TIMEOUT);
		} 
		break;
	case NETWORK_STATE_REQUESTING_IP:
	case NETWORK_STATE_DONE:
		if (securesoho_lan_get(&lan)) {
			fprintf(stderr, "##%s;%d, failed to securesoho_lan_get\n",
				       	__FUNCTION__, __LINE__);
			return 0;
		}

		if (lan.lan_type == LAN_FIXEDIP) {
			ready = 1;
			break;
		}

		if ( exist(DHCP_FLAG_FILE) ) {
			fprintf(stderr, "##%s;%d, dhcp ip got!\n", 
					__FUNCTION__, __LINE__);
			unlink("/tmp/ftp_mode");
			unlink(DHCP_FLAG_FILE);
			unlink(AUTO_FLAG_FILE);

			network_save_dhcpinfo(lan.lan_ifname);

			ready = 1;
		} else if (exist(AUTO_FLAG_FILE) ) {
			fprintf(stderr, "##%s;%d, auto ip got!\n", 
					__FUNCTION__, __LINE__);
			unlink(AUTO_FLAG_FILE);

			network_save_autoinfo(lan.lan_ifname);

			ready = 1;
		}

		if (ready) {
			network_if_conf();
			network_set_state(NETWORK_STATE_DONE);
		}
	default:
		break;
	}

	return network_task.state;
}
Пример #2
0
/* This function sends a specified buffer */
uint8_t network_send_buffer_transfert_rate(uint8_t * buffer_in,uint16_t size)
{
	static uint8_t * buffer;
	static uint16_t buffer_size;
	static uint16_t offset;
	uint8_t ASDUsize;
	uint16_t delta;
	
	if((buffer_in != NULL) && (size != 0)) 
	{
		buffer_size = size;
		buffer = buffer_in;
		offset = 0;
	}
	else
	{
		if(offset == buffer_size)
		{
			offset=0;
 			return 1;
		}
	}
	
	if(network_get_state() == APP_NETWORK_JOINED_STATE)
	{
		/* Configure the message structure */
		network_config.dstAddrMode = APS_SHORT_ADDRESS;					// Short addressing mode
		network_config.dstAddress.shortAddress = 0x00;						// Destination address	
		network_config.profileId = APP_PROFILE_ID;						// Profile ID
		network_config.dstEndpoint = APP_ENDPOINT;						// Desctination endpoint
		network_config.clusterId = APP_CLUSTER_ID;						// Desctination cluster ID
		network_config.srcEndpoint = APP_ENDPOINT;						// Source endpoint
		network_config.asdu = (uint8_t*) &zigbit_tx_buffer.message;					// application message pointer
		network_config.txOptions.acknowledgedTransmission = 0;				// Acknowledged transmission enabled
		network_config.radius = 0;										// Use maximal possible radius
		network_config.APS_DataConf = APS_DataConf;						// Confirm handler    Z
		
		delta = buffer_size - offset;
		
		if(delta > APP_MAX_PACKET_SIZE)
			ASDUsize = APP_MAX_PACKET_SIZE;
		else
			ASDUsize  = delta;
		
		memcpy(zigbit_tx_buffer.message.data,buffer+offset,ASDUsize);
		offset+=ASDUsize;
		
		/* Bitcloud sending request */
		network_set_transmission_state(APP_DATA_TRANSMISSION_WAIT_STATE);
		network_config.asduLength = ASDUsize + sizeof(zigbit_tx_buffer.message.messageId);		// actual application message length
		
		network_start_transmission();
	}
	return 0;
}
Пример #3
0
void APL_TaskHandler(void)
{
	switch (network_get_state())
	{
		case APP_INITIAL_STATE:
			
			/* Init Led */
			init_led();
			
			/* Init Serial Interface for debug */ 
  			initSerialInterface();          
			
			uid = get_uid();
			
			/* Init network */
			uid = 2;
			network_init(uid);
			
 			network_set_state(APP_NETWORK_JOIN_REQUEST);
			break;
		case APP_NETWORK_JOIN_REQUEST:
			
			/* Activate the network status led blink */
			led_start_blink();
			
			/* St	art network */
			network_start();
			
			network_set_state(APP_NETWORK_JOINING_STATE);
			
		case APP_NETWORK_JOINING_STATE:
			break;
		case APP_NETWORK_LEAVING_STATE:
			break;
		case APP_NETWORK_JOINED_STATE:
			led_stop_blink();
			break;
		default:
			break;
	}
	SYS_PostTask(APL_TASK_ID);
}