static int recv_cert (CalcHandle* handle, FlashContent* content) { int ret; int i; uint8_t buf[256]; ticalcs_strlcpy(handle->updat->text, _("Receiving certificate"), sizeof(handle->updat->text)); ticalcs_update_label(handle); content->model = handle->model; content->name[0] = 0; content->data_type = TI83p_CERT; content->device_type = 0x73; content->num_pages = 0; content->data_part = (uint8_t *)tifiles_ve_alloc_data(2 * 1024 * 1024); // 2MB max ret = SEND_REQ2(handle, 0x00, TI83p_GETCERT, "\0\0\0\0\0\0\0", 0x00); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = ticables_cable_recv(handle->cable, buf, 4); //VAR w/ no header if (!ret) { ticalcs_info(" TI->PC: VAR"); ret = SEND_ACK(handle); for (i = 0, content->data_length = 0; !ret; i++) { uint16_t block_size; ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &block_size, content->data_part); if (!ret) { ret = SEND_ACK(handle); if (!ret) { content->data_length += block_size; handle->updat->cnt2 += block_size; ticalcs_update_pbar(handle); } } } } } } } } return ret; }
static int recv_idlist (CalcHandle* handle, uint8_t* id) { int ret; uint16_t unused; uint16_t varsize; uint8_t vartype; char varname[9]; uint8_t varattr; uint8_t version; uint8_t data[16]; int i; ticalcs_strlcpy(handle->updat->text, "ID-LIST", sizeof(handle->updat->text)); ticalcs_update_label(handle); ret = SEND_REQ(handle, 0x0000, TI73_IDLIST, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { ret = RECV_ACK(handle, &unused); if (!ret) { ret = RECV_VAR(handle, &varsize, &vartype, varname, &varattr, &version); if (!ret) { ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &varsize, data); if (!ret) { ret = SEND_ACK(handle); if (!ret) { i = data[9]; data[9] = data[10]; data[10] = i; for (i = 4; i < varsize; i++) { sprintf((char *)&id[2 * (i-4)], "%02x", data[i]); } id[7*2] = '\0'; } } } } } } } } return ret; }
static int recv_backup (CalcHandle* handle, BackupContent* content) { int ret; char varname[9]; content->model = handle->model; ticalcs_strlcpy(content->comment, tifiles_comment_set_backup(), sizeof(content->comment)); if (handle->model == CALC_TI83) { ret = SEND_REQ(handle, 0x0000, TI83_BKUP, "\0\0\0\0\0\0\0"); if (!ret) { ret = RECV_ACK(handle, NULL); } if (ret) { return ret; } } else { ticalcs_strlcpy(update_->text, _("Waiting for backup..."), sizeof(update_->text)); update_label(); } varname[0] = 0; do { ret = RECV_VAR(handle, &(content->data_length1), &content->type, varname); if (ret) { break; } content->data_length2 = (uint8_t)varname[0] | (((uint16_t)(uint8_t)varname[1]) << 8); content->data_length3 = (uint8_t)varname[2] | (((uint16_t)(uint8_t)varname[3]) << 8); if (handle->model != CALC_TI86) { content->mem_address = (uint8_t)varname[4] | (((uint16_t)(uint8_t)varname[5]) << 8); } else { content->data_length4 = (uint8_t)varname[4] | (((uint16_t)(uint8_t)varname[5]) << 8); } ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); } } if (ret) { break; } update_->text[0] = 0; update_label(); update_->cnt2 = 0; update_->max2 = (handle->model != CALC_TI86) ? 3 : 4; update_->pbar(); content->data_part1 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length1, content->data_part1); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } update_->cnt2++; update_->pbar(); content->data_part2 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length2, content->data_part2); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } update_->cnt2++; update_->pbar(); if (content->data_length3) { content->data_part3 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length3, content->data_part3); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } } else { content->data_part3 = NULL; } update_->cnt2++; update_->pbar(); if (handle->model != CALC_TI86) { content->data_part4 = NULL; } else { content->data_part4 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length4, content->data_part4); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } update_->cnt2++; update_->pbar(); } } while(0); return ret; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int ret = 0; uint16_t ve_size; ticalcs_strlcpy(update_->text, _("Waiting for var(s)..."), sizeof(update_->text)); update_label(); content->model = handle->model; content->num_entries = 0; for (nvar = 0;; nvar++) { VarEntry *ve = tifiles_ve_create(); int ret2; do { update_refresh(); if (update_->cancel) { ret = ERR_ABORT; goto error; } ret = RECV_VAR(handle, &ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (ret == ERROR_READ_TIMEOUT); ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) // end of transmission { ret = 0; } goto error; } if (ret2) { ret = ret2; goto error; } ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ticonv_varname_to_utf8_sn(handle->model, ve->name, update_->text, sizeof(update_->text), ve->type); update_label(); ve->data = tifiles_ve_alloc_data(ve->size); ret = RECV_XDP(handle, &ve_size, ve->data); if (!ret) { ve->size = ve_size; ret = SEND_ACK(handle); } } } if (!ret) { tifiles_content_add_entry(content, ve); } else { error: tifiles_ve_delete(ve); break; } } if (nvar == 1) { ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment)); *vr = tifiles_ve_dup(content->entries[0]); } else { ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment)); *vr = NULL; } return ret; }
static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr) { int ret; uint16_t unused; VarEntry *ve; uint16_t ve_size; content->model = handle->model; ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment)); content->num_entries = 1; content->entries = tifiles_ve_create_array(1); ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); ticonv_varname_to_utf8_sn(handle->model, vr->name, update_->text, sizeof(update_->text), vr->type); update_label(); do { // silent request ret = SEND_REQ(handle, (uint16_t)vr->size, vr->type, vr->name); if (!ret) { ret = RECV_ACK(handle, &unused); if (!ret) { ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name); } } if (ret) { break; } ve->size = ve_size; ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); } } if (ret) { break; } ve->data = tifiles_ve_alloc_data(ve->size); ret = RECV_XDP(handle, &ve_size, ve->data); if (!ret) { ve->size = ve_size; ret = SEND_ACK(handle); } } while(0); return ret; }
static int recv_flash (CalcHandle* handle, FlashContent* content, VarRequest* vr) { int ret; FlashPage *fp; uint16_t data_addr; uint16_t old_page = 0; uint16_t data_page; uint16_t data_length; uint8_t data_type; uint32_t size; int first_block; int page; int offset; uint8_t buffer[FLASH_PAGE_SIZE + 4]; ticonv_varname_to_utf8_sn(handle->model, vr->name, handle->updat->text, sizeof(handle->updat->text), vr->type); ticalcs_update_label(handle); content->model = handle->model; ticalcs_strlcpy(content->name, vr->name, sizeof(content->name)); content->data_type = vr->type; content->device_type = handle->model == CALC_TI73 ? DEVICE_TYPE_73 : DEVICE_TYPE_83P; content->num_pages = 2048; // TI83+ has 512 KB of FLASH max content->pages = tifiles_fp_create_array(content->num_pages); page = 0; fp = content->pages[page] = tifiles_fp_create(); ret = SEND_REQ2(handle, 0x00, TI73_APPL, vr->name, 0x00); if (!ret) { ret = RECV_ACK(handle, NULL); } if (ret) { return ret; } handle->updat->cnt2 = 0; handle->updat->max2 = vr->size; for (size = 0, first_block = 1, offset = 0; !ret;) { char name[9]; int ret2; ret = RECV_VAR2(handle, &data_length, &data_type, name, &data_addr, &data_page); ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) { ret = 0; } break; } if (ret2) { ret = ret2; break; } if (first_block) { old_page = data_page; fp->addr = data_addr & 0x4000; fp->page = data_page; } if (old_page != data_page) { fp->addr = data_addr & 0x4000; fp->page = old_page; fp->flag = 0x80; fp->size = offset; fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE); memcpy(fp->data, buffer, fp->size); page++; offset = 0; old_page = data_page; fp = content->pages[page] = tifiles_fp_create(); } ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &data_length, &buffer[offset]); if (!ret) { ret = SEND_ACK(handle); } } } if (ret) { break; } if (first_block) { first_block = 0; /* compute actual application size */ if (buffer[0] == 0x80 && buffer[1] == 0x0f) { uint32_t len = ((uint32_t)(buffer[2])) << 24 | ((uint32_t)(buffer[3])) << 16 | ((uint32_t)(buffer[4])) << 8 | (uint32_t)(buffer[5]); handle->updat->max2 = len + 75; } } size += data_length; offset += data_length; handle->updat->cnt2 = size; ticalcs_update_pbar(handle); } fp->addr = data_addr & 0x4000; fp->page = old_page; fp->flag = 0x80; fp->size = offset; fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE); memcpy(fp->data, buffer, fp->size); page++; content->num_pages = page; return ret; }
static int recv_backup (CalcHandle* handle, BackupContent* content) { int ret; char varname[9]; uint8_t attr, ver; content->model = handle->model; ticalcs_strlcpy(content->comment, tifiles_comment_set_backup(), sizeof(content->comment)); varname[0] = 0; ret = SEND_REQ(handle, 0x0000, TI73_BKUP, "\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { ret = RECV_ACK(handle, NULL); } if (ret) { return ret; } do { ret = RECV_VAR(handle, &content->data_length1, &content->type, varname, &attr, &ver); if (ret) { break; } content->data_length2 = (uint8_t)varname[0] | (((uint16_t)(uint8_t)varname[1]) << 8); content->data_length3 = (uint8_t)varname[2] | (((uint16_t)(uint8_t)varname[3]) << 8); content->mem_address = (uint8_t)varname[4] | (((uint16_t)(uint8_t)varname[5]) << 8); content->version = ver; ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); } } if (ret) { break; } handle->updat->cnt2 = 0; handle->updat->max2 = 3; ticalcs_update_pbar(handle); content->data_part1 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length1, content->data_part1); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } handle->updat->cnt2++; ticalcs_update_pbar(handle); content->data_part2 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length2, content->data_part2); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } handle->updat->cnt2++; ticalcs_update_pbar(handle); content->data_part3 = tifiles_ve_alloc_data(65536); ret = RECV_XDP(handle, &content->data_length3, content->data_part3); if (!ret) { ret = SEND_ACK(handle); } if (ret) { break; } handle->updat->cnt2++; ticalcs_update_pbar(handle); content->data_part4 = NULL; } while(0); return ret; }
static int get_version (CalcHandle* handle, CalcInfos* infos) { int ret; uint16_t length; uint8_t buf[32]; ret = SEND_VER(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &length, buf); if (!ret) { ret = SEND_ACK(handle); } } } } } if (!ret) { memset(infos, 0, sizeof(CalcInfos)); if (handle->model == CALC_TI73) { ticalcs_slprintf(infos->os_version, sizeof(infos->os_version), "%1x.%02x", buf[0], buf[1]); ticalcs_slprintf(infos->boot_version, sizeof(infos->boot_version), "%1x.%02x", buf[2], buf[3]); } else { ticalcs_slprintf(infos->os_version, sizeof(infos->os_version), "%1i.%02i", buf[0], buf[1]); ticalcs_slprintf(infos->boot_version, sizeof(infos->boot_version), "%1i.%02i", buf[2], buf[3]); } infos->battery = (buf[4] & 1) ? 0 : 1; infos->hw_version = buf[5]; switch(buf[5]) { case 0: infos->model = CALC_TI83P; break; case 1: infos->model = CALC_TI83P; break; case 2: infos->model = CALC_TI84P; break; case 3: infos->model = CALC_TI84P; break; case 5: infos->model = CALC_TI84PC; break; default: infos->model = CALC_TI84PC; break; // If new models ever arise, they'll probably be 84+CSE or newer anyway. } infos->language_id = buf[6]; infos->sub_lang_id = buf[7]; infos->mask = INFOS_BOOT_VERSION | INFOS_OS_VERSION | INFOS_BATTERY | INFOS_HW_VERSION | INFOS_CALC_MODEL | INFOS_LANG_ID | INFOS_SUB_LANG_ID; tifiles_hexdump(buf, length); ticalcs_info(_(" OS: %s"), infos->os_version); ticalcs_info(_(" BIOS: %s"), infos->boot_version); ticalcs_info(_(" HW: %i"), infos->hw_version); ticalcs_info(_(" Battery: %s"), infos->battery ? _("good") : _("low")); } return ret; }
static int get_clock (CalcHandle* handle, CalcClock* _clock) { int ret; uint16_t varsize; uint8_t vartype; uint8_t varattr; uint8_t version; char varname[9]; uint8_t * buffer = handle->buffer2; uint32_t calc_time; struct tm ref, *cur; time_t r, c, now; ticalcs_strlcpy(handle->updat->text, _("Getting clock..."), sizeof(handle->updat->text)); ticalcs_update_label(handle); ret = SEND_REQ(handle, 0x0000, TI73_CLK, "\0x08\0\0\0\0\0\0\0", 0x00, 0x00); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_VAR(handle, &varsize, &vartype, varname, &varattr, &version); if (!ret) { ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &varsize, buffer); if (!ret) { ret = SEND_ACK(handle); } } } } } } } if (!ret) { calc_time = (((uint32_t)(buffer[2])) << 24) | (((uint32_t)(buffer[3])) << 16) | (((uint32_t)(buffer[4])) << 8) | (uint32_t)(buffer[5]); //printf("<%08x>\n", time); time(&now); // retrieve current DST setting memcpy(&ref, localtime(&now), sizeof(struct tm));; ref.tm_year = 1997 - 1900; ref.tm_mon = 0; ref.tm_yday = 0; ref.tm_mday = 1; ref.tm_wday = 3; ref.tm_hour = 0; ref.tm_min = 0; ref.tm_sec = 0; //ref.tm_isdst = 1; r = mktime(&ref); //printf("%s\n", asctime(&ref)); c = r + calc_time; cur = localtime(&c); //printf("%s\n", asctime(cur)); _clock->year = cur->tm_year + 1900; _clock->month = cur->tm_mon + 1; _clock->day = cur->tm_mday; _clock->hours = cur->tm_hour; _clock->minutes = cur->tm_min; _clock->seconds = cur->tm_sec; _clock->date_format = buffer[6]; _clock->time_format = buffer[7]; } return ret; }