void load_S2E_Packet_from_storage()
{
	read_storage(1, &s2e_packet, sizeof(S2E_Packet));

	if(s2e_packet.packet_size == 0x0000 || s2e_packet.packet_size == 0xFFFF){
		set_S2E_Packet_to_factory_value();
		write_storage(1, &s2e_packet, sizeof(S2E_Packet));
	}

	s2e_packet.fw_ver[0] = MAJOR_VER;
	s2e_packet.fw_ver[1] = MINOR_VER;
	s2e_packet.fw_ver[2] = MAINTENANCE_VER;
}
예제 #2
0
파일: main.c 프로젝트: ADTL/WIZ550web
int application_update(void)
{
	Firmware_Upload_Info firmware_upload_info;
	uint8_t firmup_flag = 0;

	read_storage(0, &firmware_upload_info, sizeof(Firmware_Upload_Info));
	if(firmware_upload_info.wiznet_header.stx == STX) {
		firmup_flag = 1;
	}

	if(firmup_flag) {
		uint32_t tftp_server;
		uint8_t *filename;
		int ret;

		//DBG_PRINT(INFO_DBG, "### Application Update... ###\r\n");
		tftp_server = (firmware_upload_info.tftp_info.ip[0] << 24) | (firmware_upload_info.tftp_info.ip[1] << 16) | (firmware_upload_info.tftp_info.ip[2] << 8) | (firmware_upload_info.tftp_info.ip[3]);
		filename = firmware_upload_info.filename;

		TFTP_read_request(tftp_server, filename);

		while(1) {
			ret = TFTP_run();
			if(ret != TFTP_PROGRESS)
				break;
		}

		if(ret == TFTP_SUCCESS) {
			reply_firmware_upload_done(SOCK_CONFIG);

			memset(&firmware_upload_info, 0 ,sizeof(Firmware_Upload_Info));
			write_storage(0, &firmware_upload_info, sizeof(Firmware_Upload_Info));
		}

		return ret;
	}

	return 0;
}
void reply_firmware_upload_done(uint8_t sock)
{
	uint8_t buffer[sizeof(WIZnet_Header) + sizeof(WIZnet_Firmware_Upload_Done_Reply)];
	uint32_t ptr;
	WIZnet_Firmware_Upload_Done_Reply reply;
	Firmware_Upload_Info firmware_upload_info;
	S2E_Packet *s2e_packet = get_S2E_Packet_pointer();
	uint8_t ip[4];
	uint16_t port;

	close(sock);
	socket(sock, Sn_MR_UDP, REMOTE_CLIENT_PORT, 0);

	read_storage(0, &firmware_upload_info, sizeof(Firmware_Upload_Info));

	// reply
	firmware_upload_info.wiznet_header.length = sizeof(WIZnet_Firmware_Upload_Done_Reply);
	firmware_upload_info.wiznet_header.op_code[0] = FIRMWARE_UPLOAD_DONE;
	firmware_upload_info.wiznet_header.op_code[1] = WIZNET_REPLY;

	memcpy(reply.src_mac_address, s2e_packet->network_info_common.mac, 6);

	if((firmware_upload_info.wiznet_header.valid & 0x80))
		encrypt((firmware_upload_info.wiznet_header.valid & 0x7F), (uint8_t *)&reply, sizeof(WIZnet_Firmware_Upload_Done_Reply));

	ptr = 0;
	memcpy(buffer, &firmware_upload_info.wiznet_header, sizeof(WIZnet_Header));
	ptr += sizeof(WIZnet_Header);
	memcpy(buffer + ptr, (void *)&reply, sizeof(WIZnet_Firmware_Upload_Done_Reply));
	ptr += sizeof(WIZnet_Firmware_Upload_Done_Reply);

	if(firmware_upload_info.wiznet_header.unicast == 0) {
		memset(firmware_upload_info.configtool_info.ip, 255, 4);
	}
	memcpy(ip, firmware_upload_info.configtool_info.ip, sizeof(uint8_t) * 4);
	memcpy(&port, &firmware_upload_info.configtool_info.port, sizeof(uint16_t));
	sendto(sock, buffer, ptr, ip, port);
}
예제 #4
0
 RETURN_CODE readPersistentStorage(uint16_t start_addr, uint16_t length, uint8_t* buffer)
 {
     return read_storage(start_addr, length, buffer);
 }