static bool maybe_handle_voot(voot_packet *packet, udp_header_t *udp, uint16 udp_data_length) { /* STAGE: Fix the size byte order. */ packet->header.size = ntohs(packet->header.size); switch (packet->header.type) { case VOOT_PACKET_TYPE_COMMAND: { uint32 option; option = 0; /* STAGE: Check if an option was passed along. */ if (packet->header.size >= 8) { uint8 *buffer_index; /* STAGE: The address isn't byte aligned, so we're forced to copy it this way. */ buffer_index = (uint8 *) (((uint32 *) packet->buffer) + 1); ((uint8 *) (&option))[0] = buffer_index[0]; ((uint8 *) (&option))[1] = buffer_index[1]; ((uint8 *) (&option))[2] = buffer_index[2]; ((uint8 *) (&option))[3] = buffer_index[3]; } return maybe_handle_command(packet->buffer[0], option, packet); } case VOOT_PACKET_TYPE_DATA: #if 0 /* TODO: We await the return of the trap. */ trap_inject_data(packet->buffer, packet->header.size - 1); #endif break; case VOOT_PACKET_TYPE_DUMP: dump_add(packet->buffer, packet->header.size); break; default: break; } return FALSE; }
int main(int argc, char *argv[]) { int ret = 1, i, idx; dldev_t dev; tymer_t db; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ i = strlen(argv[0]) - 1; for(; i >= 0 && argv[0][i] != '/'; i--); i++; if(strstr(argv[0] + i, "interval")){ set_timer(POR_INTERVAL); is_countdn = 0; } while((i = getopt(argc, argv, "hd:")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; #ifdef USB_USBHID dev.usb.file = dev_file; #endif if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ if((idx = find_app(&dev, uapp_name)) < 0){ ERROR("%s application not found", uapp_name); goto end; } if(dump_add(&dev, idx, &data, &len)){ ERROR("dump_add"); goto end; } read_timer(&db, data); free(data); print_timer(&db, stdout); free_timer(&db); /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } ret = 0; exit: close_dev(&dev); exit(ret); }
int main(int argc, char *argv[]) { int ret = 1, istty, i, idx; char *msg = NULL, *timer = NULL, *at_end = NULL, *halfway = NULL; dldev_t dev; tymer_t db; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ istty = isatty(0); i = strlen(argv[0]) - 1; for(; i >= 0 && argv[0][i] != '/'; i--); i++; if(strstr(argv[0] + i, "interval")){ set_timer(POR_INTERVAL); is_countdn = 0; } while((i = getopt(argc, argv, "hd:")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; #ifdef USB_USBHID dev.usb.file = dev_file; #endif BEGIN_OPT() OPT("msg", msg) OPT("timer", timer) OPT("at_end", at_end) OPT("halfway", halfway) END_OPT() /* allows the user to change only at_end in interval timer */ if(istty && ((!msg || !timer) && (is_countdn || !at_end))) usage(); if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ if((idx = find_app(&dev, uapp_name)) < 0){ ERROR("%s application not found", uapp_name); goto end; } if(dump_add(&dev, idx, &data, &len)){ ERROR("dump_add"); goto end; } read_timer(&db, data); free(data); if(!istty) add_timer_file(&db, stdin); if(msg && timer){ char buf[BUFSIZ]; timer_data_t rec; sprintf(buf, "%s\t%s\t%s%s", msg, timer, (at_end ? at_end : "stop"), (halfway && strcmp(halfway, "no") ? "\thalfway" : "")); if(read_timer_line(&rec, buf)) fprintf(stderr, "add_%s: format error!\n", lapp_name); else if(find_timer(&db, &rec) < 0) add_timer(&db, &rec); } if(!is_countdn && at_end){ int i; for(i = 0; i < 3 && strcmp(at_end, timer_at_end[i]); i++); if(i < 3){ set_timer_at_end(i); update_timer_at_end(&db); } } create_timer(&db, &data, &len); if(load_add(&dev, idx, data)){ ERROR("load_add"); goto end; } free(data); print_timer(&db, stdout); free_timer(&db); /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } ret = 0; exit: close_dev(&dev); exit(ret); }
int main(int argc, char *argv[]) { int ret = 1, i, idx, fd, num_apps = 0; char *dev_file = "/dev/uhid0", *banner, *file; dldev_t dev; appinfo *app = NULL; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ while((i = getopt(argc, argv, "hd:")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; #ifdef USB_USBHID dev.usb.file = dev_file; #endif BEGIN_OPT() APP_OPT("rom", -3) APP_OPT("eeprom", -2) APP_OPT("wristapp", -1) APP_OPT("contact", APP_CONTACT) APP_OPT("note", APP_NOTE) APP_OPT("appt", APP_APPT) APP_OPT("alarm", APP_ALARM) APP_OPT("schedule", APP_SCHEDULE) APP_OPT("occasion", APP_OCCASION) APP_OPT("chrono", APP_CHRONO) APP_OPT("countdn", APP_TIMER) APP_OPT("interval", APP_TIMER | 0x100) #if 0 APP_OPT("synchro", APP_SYNCHRO) #endif APP_OPT("option", APP_OPTION) END_OPT() if(!num_apps) usage(); if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } tucp_progress(1); if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ for(i = 0; i < num_apps; i++){ if(app[i].file[0]) fprintf(stderr, "%s\n", app[i].file); else continue; banner = NULL; file = app[i].file; switch(app[i].app){ case -3: if(dump_rom(&dev, &data, &len)){ ERROR("dump_rom"); goto end; } break; case -2: if(dump_eeprom(&dev, &data, &len)){ ERROR("dump_eeprom"); goto end; } break; case -1: banner = file; for(; *file && *file != '='; file++); if(*file) *file++ = 0; if(!(*file)){ ERROR("%s: no file name specified", banner); goto end; } for(; *banner; banner++) *banner = toupper(*banner); banner = app[i].file; break; case APP_CONTACT: banner = "CONTACT"; break; case APP_NOTE: banner = "NOTE"; break; case APP_APPT: banner = "APPT"; break; case APP_ALARM: banner = "ALARM"; break; case APP_SCHEDULE: banner = "SCHEDULE"; break; case APP_OCCASION: banner = "OCCASION"; break; case APP_CHRONO: banner = "CHRONO"; break; case APP_TIMER: banner = "COUNTDN TIMER"; break; case APP_TIMER | 0x100: banner = "INTERVAL TIMER"; break; #if 0 case APP_SYNCHRO: banner = "SYNCHRO"; break; #endif case APP_OPTION: len = 15; data = (u8 *)malloc(len); if(read_abs_addr(&dev, dev.sysmap.opt_addr, int_mem, data, len)){ ERROR("read_abs_addr"); goto end; } break; } if(banner){ if((idx = find_app(&dev, banner)) < 0){ ERROR("%s application not found", banner); goto end; } if(dump_add(&dev, idx, &data, &len)){ ERROR("dump_add"); goto end; } } if((fd = open(file, O_WRITE, S_IRWUSR)) < 0){ ERROR("%s: open failed", file); goto end; } if(write(fd, data, len) != len){ ERROR("%s: write failed", file); goto end; } close(fd); free(data); } /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } tucp_progress(0); ret = 0; exit: close_dev(&dev); exit(ret); }
int main(int argc, char *argv[]) { int ret = 1, istty, i, idx, delete_all = 0, updated = 0; dldev_t dev; contact_t db; contact_data_t rec; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ istty = isatty(0); while((i = getopt(argc, argv, "hd:a")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'a': delete_all = 1; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; #ifdef USB_USBHID dev.usb.file = dev_file; #endif memset(&rec, 0, sizeof(contact_data_t)); BEGIN_OPT() OPT("msg", rec.msg) OPT("type", rec.type) OPT("area", rec.area) OPT("number", rec.number) END_OPT() if(delete_all){ fprintf(stderr, "WARNING: DELETE ALL CONTACTS IN THE WATCH (Y/N)? "); if(tolower(getchar()) != 'y') exit(0); }else if(istty && (!rec.msg || !rec.type || !rec.area || !rec.number)) usage(); /* TODO: long phone number extending to the next or previous record */ if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ if((idx = find_app(&dev, "CONTACT")) < 0){ ERROR("CONTACT application not found"); goto end; } if(dump_add(&dev, idx, &data, &len)){ ERROR("dump_add"); goto end; } read_contact(&db, data); free(data); if(delete_all){ while(!del_contact(&db, 0)) updated = 1; }else{ if(!istty && !del_contact_file(&db, stdin)) updated = 1; if(rec.msg && rec.type && rec.area && rec.number && (i = find_contact(&db, &rec)) >= 0 && !del_contact(&db, i)) updated = 1; } if(updated){ create_contact(&db, &data, &len); if(load_add(&dev, idx, data)){ ERROR("load_add"); goto end; } free(data); } print_contact(&db, stdout); free_contact(&db); /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } ret = 0; exit: close_dev(&dev); exit(ret); }