void save_S2E_Packet_to_storage() { uint8_t state; state = s2e_packet.network_info[0].state; s2e_packet.network_info[0].state = 0; write_storage(1, &s2e_packet, sizeof(S2E_Packet)); s2e_packet.network_info[0].state = state; }
static krb5_error_code fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal primary_principal) { krb5_fcache *f = FCACHE(id); int ret = 0; int fd; char *filename = f->filename; unlink (filename); ret = fcc_open(context, id, &fd, O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, 0600); if(ret) return ret; { krb5_storage *sp; sp = krb5_storage_emem(); krb5_storage_set_eof_code(sp, KRB5_CC_END); if(context->fcache_vno != 0) f->version = context->fcache_vno; else f->version = KRB5_FCC_FVNO_4; ret |= krb5_store_int8(sp, 5); ret |= krb5_store_int8(sp, f->version); storage_set_flags(context, sp, f->version); if(f->version == KRB5_FCC_FVNO_4 && ret == 0) { /* V4 stuff */ if (context->kdc_sec_offset) { ret |= krb5_store_int16 (sp, 12); /* length */ ret |= krb5_store_int16 (sp, FCC_TAG_DELTATIME); /* Tag */ ret |= krb5_store_int16 (sp, 8); /* length of data */ ret |= krb5_store_int32 (sp, context->kdc_sec_offset); ret |= krb5_store_int32 (sp, context->kdc_usec_offset); } else { ret |= krb5_store_int16 (sp, 0); } } ret |= krb5_store_principal(sp, primary_principal); ret |= write_storage(context, sp, fd); krb5_storage_free(sp); } fcc_unlock(context, fd); if (close(fd) < 0) if (ret == 0) { ret = errno; krb5_set_error_message (context, ret, N_("close %s: %s", ""), FILENAME(id), strerror(ret)); } return ret; }
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; }
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; }
static krb5_error_code fcc_store_cred(krb5_context context, krb5_ccache id, krb5_creds *creds) { int ret; int fd; ret = fcc_open(context, id, &fd, O_WRONLY | O_APPEND | O_BINARY | O_CLOEXEC, 0); if(ret) return ret; { krb5_storage *sp; sp = krb5_storage_emem(); krb5_storage_set_eof_code(sp, KRB5_CC_END); storage_set_flags(context, sp, FCACHE(id)->version); if (!krb5_config_get_bool_default(context, NULL, TRUE, "libdefaults", "fcc-mit-ticketflags", NULL)) krb5_storage_set_flags(sp, KRB5_STORAGE_CREDS_FLAGS_WRONG_BITORDER); ret = krb5_store_creds(sp, creds); if (ret == 0) ret = write_storage(context, sp, fd); krb5_storage_free(sp); } fcc_unlock(context, fd); if (close(fd) < 0) { if (ret == 0) { ret = errno; krb5_set_error_message (context, ret, N_("close %s: %s", ""), FILENAME(id), strerror(ret)); } } return ret; }
static void process_firmware_upload_init(uint8_t sock, Remote_Info *remote_info, WIZnet_Header *wiznet_header) { S2E_Packet *value = get_S2E_Packet_pointer(); struct __network_info_common tmp; uint16_t len; WIZnet_Firmware_Upload_Init firmware_upload; uint8_t buffer[sizeof(WIZnet_Header) + sizeof(WIZnet_Firmware_Upload_Done_Reply)]; uint32_t ptr; WIZnet_Firmware_Upload_Init_Reply reply; Firmware_Upload_Info firmware_upload_info; S2E_Packet *s2e_packet = get_S2E_Packet_pointer(); uint8_t ip[4]; uint16_t port; getsockopt(sock, SO_REMAINSIZE, &len); if(len != wiznet_header->length) return; recvfrom(sock, (uint8_t *)&firmware_upload, sizeof(WIZnet_Firmware_Upload_Init), ip, &port); if(wiznet_header->op_code[0] != FIRMWARE_UPLOAD_INIT) return; if((wiznet_header->valid & 0x80)) decrypt((wiznet_header->valid & 0x7F), (uint8_t *)&firmware_upload, len); if(memcmp(firmware_upload.dst_mac_address, s2e_packet->network_info_common.mac, 6)) return; if(strcmp((char *)firmware_upload.set_pw, (char *)s2e_packet->options.pw_setting)) return; /* Storee Current Network Information (For DHCP) */ memcpy(&tmp, &(value->network_info_common), sizeof(struct __network_info_common)); load_S2E_Packet_from_storage(); memcpy(&(value->network_info_common), &tmp, sizeof(struct __network_info_common)); save_S2E_Packet_to_storage(); //write the TFTP server ip, port, filename and etc. to storage memcpy(&firmware_upload_info.wiznet_header , wiznet_header , sizeof(WIZnet_Header)); memcpy(&firmware_upload_info.configtool_info , remote_info , sizeof(Remote_Info)); memcpy(firmware_upload_info.tftp_info.ip , (uint8_t *) (firmware_upload.server_ip) , sizeof(uint8_t)*4); memcpy((uint8_t *)&(firmware_upload_info.tftp_info.port) , (uint8_t *)&(firmware_upload.server_port), sizeof(uint8_t)*2); memcpy(firmware_upload_info.filename , (uint8_t *) (firmware_upload.file_name) , sizeof(uint8_t)*50); write_storage(0, &firmware_upload_info, sizeof(Firmware_Upload_Info)); // reply wiznet_header->length = sizeof(WIZnet_Firmware_Upload_Init_Reply); wiznet_header->op_code[1] = WIZNET_REPLY; memcpy(reply.src_mac_address, s2e_packet->network_info_common.mac, 6); if((wiznet_header->valid & 0x80)) encrypt((wiznet_header->valid & 0x7F), (uint8_t *)&reply, sizeof(WIZnet_Firmware_Upload_Init_Reply)); ptr = 0; memcpy(buffer, wiznet_header, sizeof(WIZnet_Header)); ptr += sizeof(WIZnet_Header); memcpy(buffer + ptr, (void *)&reply, sizeof(WIZnet_Firmware_Upload_Init_Reply)); ptr += sizeof(WIZnet_Firmware_Upload_Init_Reply); if(wiznet_header->unicast == 0) { memset(remote_info->ip, 255, 4); } sendto(sock, buffer, ptr, remote_info->ip, remote_info->port); // Reboot to bootloader delay_cnt(100); NVIC_SystemReset(); }
RETURN_CODE writePersistentStorage(uint16_t start_addr, uint16_t length, uint8_t* buffer) { return write_storage(start_addr, length, buffer); }
void save_S2E_Packet_to_storage() { write_storage(1, &s2e_packet, sizeof(S2E_Packet)); }