void soundb_sdl_stop(void) { log_std(("sound:sdl: soundb_sdl_stop()\n")); SDL_PauseAudio(1); }
adv_error advance_ui_inner_init(struct advance_ui_context* context, adv_conf* cfg_context) { adv_conf_iterator k; adv_color_def def; context->state.ui_font = 0; context->state.ui_font_oriented = 0; if (strcmp(context->config.ui_font_buffer, "auto") != 0) { /* try reading the font, the real font is loaded later */ adv_font* font; adv_fz* f; const char* file = file_config_file_home(context->config.ui_font_buffer); log_std(("emu:ui: font '%s'\n", file)); f = fzopen(file, "rb"); if (!f) { target_err("Error opening the font %s\n", file); return -1; } font = adv_font_load(f, 16, 16); if (!font) { target_err("Error reading the font %s\n%s\n", file, error_get()); return -1; } adv_font_free(font); fzclose(f); } def = color_def_make_rgb_from_sizelenpos(3, 8, 0, 8, 8, 8, 16); if (strcmp(context->config.help_image_buffer, "auto") == 0) { adv_fz* f; unsigned i; log_std(("emu:ui: helpimage auto\n")); f = fzopenmemory(HELPIMAGE, HELPIMAGE_SIZE); context->state.help_image = adv_bitmap_load_png_rgb(f, def); if (!context->state.help_image) { target_err("Error reading the internal help image\n"); return -1; } fzclose(f); log_std(("emu:ui: helptag auto\n")); i = 0; while (HELPTAG[i]) { char* d = strdup(HELPTAG[i]); log_std(("emu:ui: helptag '%s'\n", d)); if (advance_ui_parse_help(context, d) != 0) { free(d); target_err("Invalid 'ui_helptag' option.\n%s\n", error_get()); return -1; } free(d); ++i; } } else { if (strcmp(context->config.help_image_buffer, "none") != 0) { adv_fz* f; const char* file = file_config_file_home(context->config.help_image_buffer); log_std(("emu:ui: helpimage '%s'\n", file)); f = fzopen(file, "rb"); if (!f) { target_err("Error opening the help image %s\n", file); return -1; } context->state.help_image = adv_bitmap_load_png_rgb(f, def); if (!context->state.help_image) { target_err("Error reading the help image %s\n%s\n", file, error_get()); return -1; } fzclose(f); } else { context->state.help_image = 0; } log_std(("emu:ui: helptag start\n")); for (conf_iterator_begin(&k, cfg_context, "ui_helptag"); !conf_iterator_is_end(&k); conf_iterator_next(&k)) { char* d = strdup(conf_iterator_string_get(&k)); log_std(("emu:ui: helptag '%s'\n", d)); if (advance_ui_parse_help(context, d) != 0) { free(d); target_err("Invalid 'ui_helptag' option.\n%s\n", error_get()); return -1; } free(d); } } return 0; }
/* * \brief function to parse PUBLISH packet arguments * \param argc Number of arguments. * \param argv Arguments. * \param pkt Pointer to packet. */ umqtt_ret build_publish_pkt_getopts(int argc, char **argv, struct mqtt_packet *pkt) { int ret = UMQTT_SUCCESS; int c, option_index = 0; uint16_t pkt_id = 1; char topic[MAX_TOPIC_LEN] = "\0"; char msg[1024] = "\0"; static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, {"verbose", required_argument, 0, 'v'}, {"topic", required_argument, 0, 't'}, {"message", required_argument, 0, 'm'}, {"dup", no_argument, 0, 'd'}, {"qos", required_argument, 0, 'q'}, {"retain", no_argument, 0, 'r'}, {"pkt-id", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* get arguments */ while (1) { if ((c = getopt_long(argc, argv, "hv:u:t:m:dq:rp:", long_options, &option_index)) != -1) { switch (c) { case 'h': print_usage(); ret = UMQTT_ERROR; goto end; case 'v': /* set log level */ if (optarg) { set_log_level_str(optarg); } break; case 't': /* Set topic */ if (optarg) { strcpy(topic, optarg); } else { log_std(LOG_ERROR, "The topic flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'm': /* set the message */ if (optarg) { strcpy(msg, optarg); } else { log_std(LOG_ERROR, "The message flag should be followed by a message"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'd': /* set dup flag */ pkt->fixed->publish.dup = 1; break; case 'r': /* set retain flag */ pkt->fixed->publish.retain = 1; break; case 'q': /* set the QoS */ if (optarg) { pkt->fixed->publish.qos = (0x03 & (uint8_t)atoi(optarg)); } else { log_std(LOG_ERROR, "The QoS flag should be followed by a QoS (0-3)"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'p': /* Set Packet Identifier */ if (optarg) { pkt_id = (uint16_t)atoi(optarg); generate_packet_id(pkt_id); } else { log_std(LOG_ERROR, "The packet identifier flag should be followed by a packet id"); print_usage(); ret = UMQTT_ERROR; goto end; } break; } } else { /* Final arguement */ break; } } if (topic[0] == '\0') { log_std(LOG_INFO, "Automatically generating a topic since none was specified"); } /* set publish variable header and message payload */ ret = set_publish_variable_header(pkt, topic, strlen(topic)); if (ret) { log_std(LOG_ERROR, "Failed to assign PUBLISH packet variable header"); goto end; } ret = init_packet_payload(pkt, PUBLISH, (uint8_t *)msg, strlen(msg)); if (ret) { log_std(LOG_ERROR, "Failed to assign PUBLISH packet payload"); goto end; } end: return ret; }
adv_error joystickb_lgrawinput_init(int joystickb_id) { #if defined(USE_SDL) && SDL_MAJOR_VERSION != 1 error_set("Incompatible with SDL2.\n"); return -1; #else unsigned i; HMODULE h; UINT n; UINT size; RAWINPUTDEVICELIST* l; log_std(("joystickb:lgrawinput: joystickb_lgrawinput_init(id:%d)\n", joystickb_id)); h = GetModuleHandle("user32.dll"); if (!h) { error_set("Error loading the user32 library.\n"); return -1; } RegisterRawInputDevices_ptr = (RegisterRawInputDevices_type)GetProcAddress(h, "RegisterRawInputDevices"); GetRawInputDeviceList_ptr = (GetRawInputDeviceList_type)GetProcAddress(h, "GetRawInputDeviceList"); GetRawInputDeviceInfoA_ptr = (GetRawInputDeviceInfoA_type)GetProcAddress(h, "GetRawInputDeviceInfoA"); GetRawInputData_ptr = (GetRawInputData_type)GetProcAddress(h, "GetRawInputData"); if (!RegisterRawInputDevices_ptr || !GetRawInputDeviceList_ptr || !GetRawInputDeviceInfoA_ptr || !GetRawInputData_ptr) { error_set("Raw input devices not supported on your system.\n"); return -1; } if (GetRawInputDeviceList_ptr(NULL, &n, sizeof(RAWINPUTDEVICELIST)) != 0) { error_set("Error getting the number of raw devices.\n"); return -1; } if (n == 0) { error_set("No input device found.\n"); return -1; } size = n * sizeof(RAWINPUTDEVICELIST); l = malloc(size); n = GetRawInputDeviceList_ptr(l, &size, sizeof(RAWINPUTDEVICELIST)); if (n == -1) { free(l); error_set("Error getting the list of raw devices.\n"); return -1; } log_std(("joystickb:lgrawinput: GetRawInputDeviceList() -> %d\n", (unsigned)n)); raw_state.mac = 0; for (i = 0; i < n; ++i) { if (raw_state.mac < RAW_MOUSE_MAX) { UINT size; unsigned vid, pid, rev; struct raw_context* context = &raw_state.map[raw_state.mac].context; size = sizeof(RID_DEVICE_INFO); context->info.cbSize = sizeof(RID_DEVICE_INFO); if (GetRawInputDeviceInfoA_ptr(l[i].hDevice, RIDI_DEVICEINFO, &context->info, &size) == -1) { continue; } size = sizeof(context->name); if (GetRawInputDeviceInfoA_ptr(l[i].hDevice, RIDI_DEVICENAME, context->name, &size) < 0) { continue; } /* Get the VID/PID */ if (GetRawInputDeviceHIDInfo(context->name, &vid, &pid, &rev) < 0) { /* on error use fake value, for not HID devices it's ok to fail */ vid = 0; pid = 0; rev = 0; } log_std(("joystickb:lgrawinput: GetRawInputDeviceInfo(%d) -> type:%d,vid:%04x,pid:%04x,rev:%04x,%s\n", i, (unsigned)context->info.dwType, vid, pid, rev, context->name)); /* only mouse type lightgun are recognized */ if (context->info.dwType != RIM_TYPEMOUSE) { continue; } if ( /* SMOG Lightgun (http://lightgun.splinder.com/) */ (vid == 0x0b9a && pid == 0x016a) /* Acts Labs Lightgun (http://www.act-labs.com/) */ || (vid == 0x061c && pid == 0xa800) || (vid == 0x061c && pid == 0xa700) ) { /* recognized */ } else { continue; } raw_state.map[raw_state.mac].context.h = l[i].hDevice; log_std(("joystickb:lgrawinput: lightgun id:%d,vid:%04x,pid:%04x,rev:%04x,buttons:%d,samplerate:%d\n", (unsigned)context->info.mouse.dwId, vid, pid, rev, (unsigned)context->info.mouse.dwNumberOfButtons, (unsigned)context->info.mouse.dwSampleRate)); joystickb_setup(&raw_state.map[raw_state.mac], context->info.mouse.dwNumberOfButtons); ++raw_state.mac; } } free(l); if (raw_state.mac == 0) { error_set("No lightgun found.\n"); return -1; } qsort(raw_state.map, raw_state.mac, sizeof(raw_state.map[0]), joystickb_compare); return 0; #endif }
static void raw_event(RAWINPUT* r) { unsigned i; RAWMOUSE* m; struct raw_context* c; if (r->header.dwType != RIM_TYPEMOUSE) { log_std(("WARNING:joystickb:lgrawinput: not a mouse device\n")); return; } /* search the device */ for (i = 0; i < raw_state.mac; ++i) if (r->header.hDevice == raw_state.map[i].context.h) break; if (i == raw_state.mac) { log_std(("WARNING:joystickb:lgrawinput: input device not found\n")); return; } m = &r->data.mouse; c = &raw_state.map[i].context; log_debug(("joystickb:lgrawinput: device:%d -> usFlags:%d,usButtonFlags:%d,ulRawButtons:%d,lLastX:%d,lLastY:%d,ulExtraInformation:%d\n", i, (unsigned)m->usFlags, (unsigned)m->usButtonFlags, (unsigned)m->ulRawButtons, (unsigned)m->lLastX, (unsigned)m->lLastY, (unsigned)m->ulExtraInformation)); if (m->usFlags & MOUSE_MOVE_ABSOLUTE) { /* absolute */ c->x = m->lLastX; c->y = m->lLastY; } else { log_std(("WARNING:joystickb:lgrawinput: device:%d relative move\n", i)); } if (m->usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) c->button |= 0x1; if (m->usButtonFlags & RI_MOUSE_BUTTON_1_UP) c->button &= ~0x1; if (m->usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) c->button |= 0x2; if (m->usButtonFlags & RI_MOUSE_BUTTON_2_UP) c->button &= ~0x2; if (m->usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) c->button |= 0x4; if (m->usButtonFlags & RI_MOUSE_BUTTON_3_UP) c->button &= ~0x4; if (m->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) c->button |= 0x8; if (m->usButtonFlags & RI_MOUSE_BUTTON_4_UP) c->button &= ~0x8; if (m->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) c->button |= 0x10; if (m->usButtonFlags & RI_MOUSE_BUTTON_5_UP) c->button &= ~0x10; /* update autocalibration */ if (c->lx == 0 && c->hx == 0) { c->lx = c->x; c->hx = c->x; } else { if (c->x < c->lx) c->lx = c->x; if (c->x > c->hx) c->hx = c->x; } if (c->ly == 0 && c->hy == 0) { c->ly = c->y; c->hy = c->y; } else { if (c->y < c->ly) c->ly = c->y; if (c->y > c->hy) c->hy = c->y; } if (raw_option.calibration == CALIBRATION_AUTO) { c->x_adj = joystickb_adjust_analog(c->x, c->lx, c->hx); c->y_adj = joystickb_adjust_analog(c->y, c->ly, c->hy); } else if (raw_option.calibration == CALIBRATION_NONE) { c->x_adj = joystickb_adjust_analog(c->x, 0, 65536); c->y_adj = joystickb_adjust_analog(c->y, 0, 65536); } else { c->x_adj = 0; c->y_adj = 0; } log_debug(("joystickb:lgrawinput: id:%d,x:%d[%d:%d>%d],y:%d[%d:%d>%d],button:%d\n", i, c->x, c->lx, c->hx, c->x_adj, c->y, c->ly, c->hy, c->y_adj, c->button)); }
void mouseb_svgalib_done(void) { log_std(("mouseb:svgalib: mouseb_svgalib_done()\n")); }
static int action_format(int arg) { struct crypt_device *cd = NULL; struct crypt_params_integrity params = { .journal_size = opt_journal_size, .interleave_sectors = opt_interleave_sectors, /* in bitmap mode we have to overload these values... */ .journal_watermark = opt_integrity_bitmap ? opt_bitmap_sectors_per_bit : opt_journal_watermark, .journal_commit_time = opt_integrity_bitmap ? opt_bitmap_flush_time : opt_journal_commit_time, .buffer_sectors = opt_buffer_sectors, .tag_size = opt_tag_size, .sector_size = opt_sector_size ?: SECTOR_SIZE, }; char integrity[MAX_CIPHER_LEN], journal_integrity[MAX_CIPHER_LEN], journal_crypt[MAX_CIPHER_LEN]; char *integrity_key = NULL, *msg = NULL; int r; size_t signatures; if (opt_integrity) { r = crypt_parse_hash_integrity_mode(opt_integrity, integrity); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.integrity = integrity; } if (opt_journal_integrity) { r = crypt_parse_hash_integrity_mode(opt_journal_integrity, journal_integrity); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.journal_integrity = journal_integrity; } if (opt_journal_crypt) { r = crypt_parse_hash_integrity_mode(opt_journal_crypt, journal_crypt); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.journal_crypt = journal_crypt; } r = _read_keys(&integrity_key, ¶ms); if (r) goto out; r = crypt_init_data_device(&cd, action_argv[0], opt_data_device); if (r < 0) goto out; r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), action_argv[0]); if (r == -1) { r = -ENOMEM; goto out; } r = yesDialog(msg, _("Operation aborted.\n")) ? 0 : -EINVAL; free(msg); if (r < 0) goto out; r = tools_detect_signatures(action_argv[0], 0, &signatures); if (r < 0) goto out; /* Signature candidates found */ if (signatures && ((r = tools_wipe_all_signatures(action_argv[0])) < 0)) goto out; r = crypt_format(cd, CRYPT_INTEGRITY, NULL, NULL, NULL, NULL, 0, ¶ms); if (r < 0) /* FIXME: call wipe signatures again */ goto out; if (!opt_batch_mode) log_std(_("Formatted with tag size %u, internal integrity %s.\n"), opt_tag_size, opt_integrity); if (!opt_no_wipe) r = _wipe_data_device(cd, integrity_key); out: crypt_safe_free(integrity_key); crypt_safe_free(CONST_CAST(void*)params.journal_integrity_key); crypt_safe_free(CONST_CAST(void*)params.journal_crypt_key); crypt_free(cd); return r; } static int action_open(int arg) { struct crypt_device *cd = NULL; struct crypt_params_integrity params = { /* in bitmap mode we have to overload these values... */ .journal_watermark = opt_integrity_bitmap ? opt_bitmap_sectors_per_bit : opt_journal_watermark, .journal_commit_time = opt_integrity_bitmap ? opt_bitmap_flush_time : opt_journal_commit_time, .buffer_sectors = opt_buffer_sectors, }; uint32_t activate_flags = 0; char integrity[MAX_CIPHER_LEN], journal_integrity[MAX_CIPHER_LEN], journal_crypt[MAX_CIPHER_LEN]; char *integrity_key = NULL; int r; if (opt_integrity) { r = crypt_parse_hash_integrity_mode(opt_integrity, integrity); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.integrity = integrity; } if (opt_journal_integrity) { r = crypt_parse_hash_integrity_mode(opt_journal_integrity, journal_integrity); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.journal_integrity = journal_integrity; } if (opt_journal_crypt) { r = crypt_parse_hash_integrity_mode(opt_journal_crypt, journal_crypt); if (r < 0) { log_err(_("No known integrity specification pattern detected.")); return r; } params.journal_crypt = journal_crypt; } if (opt_integrity_nojournal || opt_integrity_bitmap) activate_flags |= CRYPT_ACTIVATE_NO_JOURNAL; if (opt_integrity_recovery) activate_flags |= CRYPT_ACTIVATE_RECOVERY; if (opt_integrity_bitmap) activate_flags |= CRYPT_ACTIVATE_NO_JOURNAL_BITMAP; if (opt_integrity_recalculate) activate_flags |= CRYPT_ACTIVATE_RECALCULATE; r = _read_keys(&integrity_key, ¶ms); if (r) goto out; if ((r = crypt_init_data_device(&cd, action_argv[0], opt_data_device))) goto out; r = crypt_load(cd, CRYPT_INTEGRITY, ¶ms); if (r) goto out; r = crypt_activate_by_volume_key(cd, action_argv[1], integrity_key, opt_integrity_key_size, activate_flags); out: crypt_safe_free(integrity_key); crypt_safe_free(CONST_CAST(void*)params.journal_integrity_key); crypt_safe_free(CONST_CAST(void*)params.journal_crypt_key); crypt_free(cd); return r; } static int action_close(int arg) { struct crypt_device *cd = NULL; int r; r = crypt_init_by_name(&cd, action_argv[0]); if (r == 0) r = crypt_deactivate(cd, action_argv[0]); crypt_free(cd); return r; } static int action_status(int arg) { crypt_status_info ci; struct crypt_active_device cad; struct crypt_params_integrity ip = {}; struct crypt_device *cd = NULL; char *backing_file; const char *device, *metadata_device; int path = 0, r = 0; /* perhaps a path, not a dm device name */ if (strchr(action_argv[0], '/')) path = 1; ci = crypt_status(NULL, action_argv[0]); switch (ci) { case CRYPT_INVALID: r = -EINVAL; break; case CRYPT_INACTIVE: if (path) log_std("%s is inactive.\n", action_argv[0]); else log_std("%s/%s is inactive.\n", crypt_get_dir(), action_argv[0]); r = -ENODEV; break; case CRYPT_ACTIVE: case CRYPT_BUSY: if (path) log_std("%s is active%s.\n", action_argv[0], ci == CRYPT_BUSY ? " and is in use" : ""); else log_std("%s/%s is active%s.\n", crypt_get_dir(), action_argv[0], ci == CRYPT_BUSY ? " and is in use" : ""); r = crypt_init_by_name_and_header(&cd, action_argv[0], NULL); if (r < 0) goto out; log_std(" type: %s\n", crypt_get_type(cd) ?: "n/a"); r = crypt_get_active_device(cd, action_argv[0], &cad); if (r < 0) goto out; r = crypt_get_integrity_info(cd, &ip); if (r < 0) goto out; log_std(" tag size: %u\n", ip.tag_size); log_std(" integrity: %s\n", ip.integrity ?: "(none)"); device = crypt_get_device_name(cd); metadata_device = crypt_get_metadata_device_name(cd); log_std(" device: %s%s\n", device, metadata_device ? " (detached)" : ""); if (crypt_loop_device(device)) { backing_file = crypt_loop_backing_file(device); log_std(" loop: %s\n", backing_file); free(backing_file); } if (metadata_device) { log_std(" metadata device: %s\n", metadata_device); if (crypt_loop_device(metadata_device)) { backing_file = crypt_loop_backing_file(metadata_device); log_std(" loop: %s\n", backing_file); free(backing_file); } } log_std(" sector size: %u bytes\n", crypt_get_sector_size(cd)); log_std(" interleave sectors: %u\n", ip.interleave_sectors); log_std(" size: %" PRIu64 " sectors\n", cad.size); log_std(" mode: %s%s\n", cad.flags & CRYPT_ACTIVATE_READONLY ? "readonly" : "read/write", cad.flags & CRYPT_ACTIVATE_RECOVERY ? " recovery" : ""); log_std(" failures: %" PRIu64 "\n", crypt_get_active_integrity_failures(cd, action_argv[0])); if (cad.flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) { log_std(" bitmap 512-byte sectors per bit: %u\n", ip.journal_watermark); log_std(" bitmap flush interval: %u ms\n", ip.journal_commit_time); } if (cad.flags & CRYPT_ACTIVATE_NO_JOURNAL) { log_std(" journal: not active\n"); } else { log_std(" journal size: %" PRIu64 " bytes\n", ip.journal_size); log_std(" journal watermark: %u%%\n", ip.journal_watermark); log_std(" journal commit time: %u ms\n", ip.journal_commit_time); if (ip.journal_integrity) log_std(" journal integrity MAC: %s\n", ip.journal_integrity); if (ip.journal_crypt) log_std(" journal encryption: %s\n", ip.journal_crypt); } } out: crypt_free(cd); if (r == -ENOTSUP) r = 0; return r; return -EINVAL; } static int action_dump(int arg) { struct crypt_device *cd = NULL; struct crypt_params_integrity params = {}; int r; if ((r = crypt_init(&cd, action_argv[0]))) return r; r = crypt_load(cd, CRYPT_INTEGRITY, ¶ms); if (!r) crypt_dump(cd); crypt_free(cd); return r; } static struct action_type { const char *type; int (*handler)(int); int required_action_argc; const char *arg_desc; const char *desc; } action_types[] = { { "format", action_format, 1, N_("<integrity_device>"),N_("format device") }, { "open", action_open, 2, N_("<integrity_device> <name>"),N_("open device as <name>") }, { "close", action_close, 1, N_("<name>"),N_("close device (deactivate and remove mapping)") }, { "status", action_status, 1, N_("<name>"),N_("show active device status") }, { "dump", action_dump, 1, N_("<integrity_device>"),N_("show on-disk information") }, { NULL, NULL, 0, NULL, NULL } }; static void help(poptContext popt_context, enum poptCallbackReason reason __attribute__((unused)), struct poptOption *key, const char *arg __attribute__((unused)), void *data __attribute__((unused))) { struct action_type *action; if (key->shortName == '?') { log_std("%s %s\n", PACKAGE_INTEGRITY, PACKAGE_VERSION); poptPrintHelp(popt_context, stdout, 0); log_std(_("\n" "<action> is one of:\n")); for(action = action_types; action->type; action++) log_std("\t%s %s - %s\n", action->type, _(action->arg_desc), _(action->desc)); log_std(_("\n" "<name> is the device to create under %s\n" "<integrity_device> is the device containing data with integrity tags\n"), crypt_get_dir()); log_std(_("\nDefault compiled-in dm-integrity parameters:\n" "\tTag size: %u bytes, Checksum algorithm: %s\n"), DEFAULT_TAG_SIZE, DEFAULT_ALG_NAME); exit(EXIT_SUCCESS); } else usage(popt_context, EXIT_SUCCESS, NULL, NULL); } static int run_action(struct action_type *action) { int r; log_dbg("Running command %s.", action->type); r = action->handler(0); show_status(r); return translate_errno(r); }
int os_main(int argc, char* argv[]) { int keyboard_id; adv_conf* context; const char* s; char* section_map[1]; const char** file_map; unsigned file_mac; int i; double latency_time; double buffer_time; double volume; unsigned rate; int attenuation; adv_bool opt_log; adv_bool opt_logsync; opt_log = 0; opt_logsync = 0; file_map = 0; file_mac = 0; context = conf_init(); if (os_init(context) != 0) goto err_conf; mixer_reg(context); conf_int_register_limit_default(context, "sound_volume", -32, 0, 0); conf_int_register_limit_default(context, "sound_samplerate", 5000, 96000, 44100); conf_float_register_limit_default(context, "sound_latency", 0.01, 2.0, 0.1); conf_float_register_limit_default(context, "sound_buffer", 0.05, 2.0, 0.1); if (conf_input_args_load(context, 0, "", &argc, argv, error_callback, 0) != 0) goto err_os; file_map = malloc(argc * sizeof(const char*)); for(i=1;i<argc;++i) { if (target_option_compare(argv[i], "log")) { opt_log = 1; } else if (target_option_compare(argv[i], "logsync")) { opt_logsync = 1; } else if (target_option_extract(argv[i]) == 0) { file_map[file_mac++] = argv[i]; } else { target_err("Unknown command line option '%s'.\n", argv[i]); goto err_os; } } if (argc <= 1 || file_mac == 0) { target_err("Syntax: advs FILES...\n"); goto err_os; } if (opt_log || opt_logsync) { const char* log = "advs.log"; remove(log); log_init(log, opt_logsync); } section_map[0] = ""; conf_section_set(context, section_map, 1); if (mixer_load(context) != 0) { goto err_os; } attenuation = conf_int_get_default(context, "sound_volume"); latency_time = conf_float_get_default(context, "sound_latency"); buffer_time = conf_float_get_default(context, "sound_buffer"); rate = conf_int_get_default(context, "sound_samplerate"); volume = 1.0; while (attenuation++ < 0) volume /= 1.122018454; /* = (10 ^ (1/20)) = 1dB */ if (os_inner_init("AdvanceSOUND") != 0) goto err_os; if (file_mac > MIXER_CHANNEL_MAX) { target_err("Too many files\n"); goto err_os_inner; } if (mixer_init(rate, file_mac, 1, buffer_time + latency_time, latency_time) != 0) { target_err("%s\n", error_get()); goto err_os_inner; } mixer_volume(volume); for(i=0;i<file_mac;++i) run(i, file_map[i]); free(file_map); signal(SIGINT, sigint); while (!done) { for(i=0;i<file_mac;++i) if (mixer_is_playing(i)) break; if (i==file_mac) break; mixer_poll(); target_idle(); } log_std(("s: shutdown\n")); mixer_done(); os_inner_done(); log_std(("s: the end\n")); if (opt_log || opt_logsync) { log_done(); } os_done(); conf_done(context); return EXIT_SUCCESS; err_os_inner: os_inner_done(); log_done(); err_os: os_done(); err_conf: conf_done(context); err: return EXIT_FAILURE; }
void fb_crtc_container_insert_default(adv_crtc_container* cc) { log_std(("video:fb: fb_crtc_container_insert_default()\n")); crtc_container_insert_default_modeline_svga(cc); }
void inputb_tty_done(void) { log_std(("inputb:tty: inputb_tty_done()\n")); }
static adv_error joystickb_setup(struct joystick_item_context* item, int f) { unsigned char key_bitmask[KEY_MAX/8 + 1]; unsigned char abs_bitmask[ABS_MAX/8 + 1]; unsigned char rel_bitmask[REL_MAX/8 + 1]; unsigned i; unsigned short device_info[4]; struct button_entry { int code; const char* name; } button_map[] = { #ifdef BTN_TRIGGER { BTN_TRIGGER, "trigger" }, /* joystick */ #endif #ifdef BTN_THUMB { BTN_THUMB, "thumb" }, /* joystick */ #endif #ifdef BTN_THUMB2 { BTN_THUMB2, "thumb2" }, /* joystick */ #endif #ifdef BTN_TOP { BTN_TOP, "top" }, /* joystick */ #endif #ifdef BTN_TOP2 { BTN_TOP2, "top2" }, /* joystick */ #endif #ifdef BTN_PINKIE { BTN_PINKIE, "pinkie" }, /* joystick */ #endif #ifdef BTN_BASE { BTN_BASE, "base" }, /* joystick */ #endif #ifdef BTN_BASE2 { BTN_BASE2, "base2" }, /* joystick */ #endif #ifdef BTN_BASE3 { BTN_BASE3, "base3" }, /* joystick */ #endif #ifdef BTN_BASE4 { BTN_BASE4, "base4" }, /* joystick */ #endif #ifdef BTN_BASE5 { BTN_BASE5, "base5" }, /* joystick */ #endif #ifdef BTN_BASE6 { BTN_BASE6, "base6" }, /* joystick */ #endif #ifdef BTN_DEAD { BTN_DEAD, "dead" }, /* joystick */ #endif #ifdef BTN_A { BTN_A, "a" }, /* gamepad */ #endif #ifdef BTN_B { BTN_B, "b" }, /* gamepad */ #endif #ifdef BTN_C { BTN_C, "c" }, /* gamepad */ #endif #ifdef BTN_X { BTN_X, "x" }, /* gamepad */ #endif #ifdef BTN_Y { BTN_Y, "y" }, /* gamepad */ #endif #ifdef BTN_Z { BTN_Z, "z" }, /* gamepad */ #endif #ifdef BTN_TL { BTN_TL, "tl" }, /* gamepad (top left) */ #endif #ifdef BTN_TR { BTN_TR, "tr" }, /* gamepad (top right) */ #endif #ifdef BTN_TL2 { BTN_TL2, "tl2" }, /* gamepad (top left 2) */ #endif #ifdef BTN_TR2 { BTN_TR2, "tr2" }, /* gamepad (top right 2) */ #endif #ifdef BTN_SELECT { BTN_SELECT, "select" }, /* gamepad */ #endif #ifdef BTN_START { BTN_START, "start" }, /* gamepad */ #endif #ifdef BTN_MODE { BTN_MODE, "mode" }, /* gamepad */ #endif #ifdef BTN_THUMBL { BTN_THUMBL, "thumbl" }, /* gamepad (thumb left) */ #endif #ifdef BTN_THUMBR { BTN_THUMBR, "thumbr" }, /* gamepad (thumb right) */ #endif #ifdef BTN_GEAR_DOWN { BTN_GEAR_DOWN, "gear_down" }, /* wheel */ #endif #ifdef BTN_GEAR_UP { BTN_GEAR_UP, "gear_up" }, /* wheel */ #endif #ifdef BTN_0 { BTN_0, "0" }, /* misc */ #endif #ifdef BTN_1 { BTN_1, "1" }, /* misc */ #endif #ifdef BTN_2 { BTN_2, "2" }, /* misc */ #endif #ifdef BTN_3 { BTN_3, "3" }, /* misc */ #endif #ifdef BTN_4 { BTN_4, "4" }, /* misc */ #endif #ifdef BTN_5 { BTN_5, "5" }, /* misc */ #endif #ifdef BTN_6 { BTN_6, "6" }, /* misc */ #endif #ifdef BTN_7 { BTN_7, "7" }, /* misc */ #endif #ifdef BTN_8 { BTN_8, "8" }, /* misc */ #endif #ifdef BTN_9 { BTN_9, "9" }, /* misc */ #endif #ifdef BTN_LEFT { BTN_LEFT, "left" }, /* ball */ #endif #ifdef BTN_RIGHT { BTN_RIGHT, "right" }, /* ball */ #endif #ifdef BTN_MIDDLE { BTN_MIDDLE, "middle" }, /* ball/lightgun first button */ #endif #ifdef BTN_SIDE { BTN_SIDE, "side" }, /* ball/lightgun second button */ #endif #ifdef BTN_EXTRA { BTN_EXTRA, "extra" }, /* ball */ #endif #ifdef BTN_FORWARD { BTN_FORWARD, "forward" }, /* ball */ #endif #ifdef BTN_BACK { BTN_BACK, "back" } /* ball */ #endif }; /* WARNING: It must be syncronized with the list in event.c */ struct stick_entry { struct axe_entry { int code; const char* name; } axe_map[7]; const char* name; } stick_map[] = { { { { ABS_X, "x" }, { ABS_Y, "y" }, { ABS_Z, "z" }, { ABS_RX, "rx" }, { ABS_RY, "ry" }, { ABS_RZ, "rz" }, { ABS_UNASSIGNED, 0 } }, "stick" }, #ifdef ABS_GAS { { { ABS_GAS, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "gas" }, /* IT:acceleratore */ #endif #ifdef ABS_BRAKE { { { ABS_BRAKE, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "brake" }, /* IT:freno */ #endif #ifdef ABS_WHEEL { { { ABS_WHEEL, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "wheel" }, /* IT:volante */ #endif #ifdef ABS_HAT0X { { { ABS_HAT0X, "x" }, { ABS_HAT0Y, "y" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "hat" }, /* IT:mini joystick digitale */ #endif #ifdef ABS_HAT1X { { { ABS_HAT1X, "x" }, { ABS_HAT1Y, "y" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "hat2" }, #endif #ifdef ABS_HAT2X { { { ABS_HAT2X, "x" }, { ABS_HAT2Y, "y" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "hat3" }, #endif #ifdef ABS_HAT3X { { { ABS_HAT3X, "x" }, { ABS_HAT3Y, "y" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "hat4" }, #endif #ifdef ABS_THROTTLE { { { ABS_THROTTLE, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "throttle" }, #endif #ifdef ABS_RUDDER { { { ABS_RUDDER, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "rudder" }, /* IT:timone */ #endif /* { { { ABS_PRESSURE, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "pressure" }, */ /* tablet */ /* { { { ABS_DISTANCE, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "distance" }, */ /* tablet */ /* { { { ABS_TILT_X, "x" }, { ABS_TILT_Y, "y" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "tilt" }, */ /* tablet */ /* { { { ABS_VOLUME, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "volume" }, */ /* not an action control */ #ifdef ABS_MISC { { { ABS_MISC, "mono" }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 }, { ABS_UNASSIGNED, 0 } }, "misc" } #endif }; struct rel_entry { int code; const char* name; } rel_map[] = { #ifdef REL_X { REL_X, "x" }, #endif #ifdef REL_Y { REL_Y, "y" }, #endif #ifdef REL_Z { REL_Z, "z" }, #endif #ifdef REL_WHEEL { REL_WHEEL, "wheel" }, /* (IT: rotella del mouse verticale) */ #endif #ifdef REL_HWHEEL { REL_HWHEEL, "hwheel" }, /* (IT: rotella del mouse orizzontale) */ #endif #ifdef REL_DIAL { REL_DIAL, "dial" }, /* (IT: manopola che gira) */ #endif #ifdef REL_MISC { REL_MISC, "misc" } #endif }; item->f = f; #ifdef USE_ACTLABS_HACK item->actlabs_hack_enable = 0; #endif if (ioctl(f, EVIOCGID, &device_info)) { log_std(("event: error in ioctl(EVIOCGID)\n")); item->vendor_id = 0; item->device_id = 0; item->version_id = 0; item->bus_id = 0; } else { item->vendor_id = device_info[ID_VENDOR]; item->device_id = device_info[ID_PRODUCT]; item->version_id = device_info[ID_VERSION]; item->bus_id = device_info[ID_BUS]; } memset(key_bitmask, 0, sizeof(key_bitmask)); if (event_test_bit(EV_KEY, item->evtype_bitmask)) { if (ioctl(f, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) < 0) { log_std(("event: error in ioctl(EVIOCGBIT(EV_KEY,%d))\n", (int)KEY_MAX)); return -1; } } item->button_mac = 0; for(i=0;i<sizeof(button_map)/sizeof(button_map[0]);++i) { if (event_test_bit(button_map[i].code, key_bitmask)) { if (item->button_mac < EVENT_JOYSTICK_BUTTON_MAX) { item->button_map[item->button_mac].code = button_map[i].code; item->button_map[item->button_mac].state = 0; sncpy(item->button_map[item->button_mac].name, sizeof(item->button_map[item->button_mac].name), button_map[i].name); ++item->button_mac; } } } memset(abs_bitmask, 0, sizeof(abs_bitmask)); if (event_test_bit(EV_ABS, item->evtype_bitmask)) { if (ioctl(f, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0) { log_std(("event: error in ioctl(EVIOCGBIT(EV_ABS,%d))\n", (int)ABS_MAX)); return -1; } } item->stick_mac = 0; for(i=0;i<sizeof(stick_map)/sizeof(stick_map[0]);++i) { if (item->stick_mac < EVENT_JOYSTICK_STICK_MAX) { unsigned j; struct joystick_stick_context* stick = item->stick_map + item->stick_mac; stick->axe_mac = 0; sncpy(stick->name, sizeof(stick->name), stick_map[i].name); for(j=0;stick_map[i].axe_map[j].code != ABS_UNASSIGNED;++j) { int code = stick_map[i].axe_map[j].code; if (event_test_bit(code, abs_bitmask)) { if (stick->axe_mac < EVENT_JOYSTICK_AXE_MAX) { struct joystick_axe_context* axe = stick->axe_map + stick->axe_mac; int features[5]; axe->code = code; sncpy(axe->name, sizeof(axe->name), stick_map[i].axe_map[j].name); memset(features, 0, sizeof(features)); if (ioctl(f, EVIOCGABS(code), features) < 0) { axe->min = 0; axe->max = 0; axe->fuzz = 0; axe->flat = 0; axe->digit_low = -32; axe->digit_high = 32; axe->value = 0; axe->value_adj = 0; } else { int middle = (features[1] + features[2]) / 2; int size = features[2] - features[1]; int flat = features[4]; axe->min = features[1]; axe->max = features[2]; axe->fuzz = features[3]; axe->flat = features[4]; axe->digit_low = middle - flat - (size - flat) / 8; axe->digit_high = middle + flat + (size - flat) / 8; axe->value = middle; axe->value_adj = 0; } ++stick->axe_mac; } } } /* save the stick only if it hash some axes */ if (stick->axe_mac) ++item->stick_mac; } } memset(rel_bitmask, 0, sizeof(rel_bitmask)); if (event_test_bit(EV_REL, item->evtype_bitmask)) { if (ioctl(f, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) < 0) { log_std(("event: error in ioctl(EVIOCGBIT(EV_REL,%d))\n", (int)REL_MAX)); return -1; } } item->rel_mac = 0; for(i=0;i<sizeof(rel_map)/sizeof(rel_map[0]);++i) { if (event_test_bit(rel_map[i].code, rel_bitmask)) { if (item->rel_mac < EVENT_JOYSTICK_REL_MAX) { item->rel_map[item->rel_mac].code = rel_map[i].code; item->rel_map[item->rel_mac].value = 0; sncpy(item->rel_map[item->rel_mac].name, sizeof(item->rel_map[item->rel_mac].name), rel_map[i].name); ++item->rel_mac; } } } return 0; }
static void raw_event(RAWINPUT* r) { unsigned i; RAWMOUSE* m; struct raw_context* c; if (r->header.dwType != RIM_TYPEMOUSE) { log_std(("WARNING:mouseb:rawinput: not a mouse device\n")); return; } /* search the device */ for (i = 0; i < raw_state.mac; ++i) if (r->header.hDevice == raw_state.map[i].context.h) break; if (i == raw_state.mac) { log_std(("WARNING:mouseb:rawinput: input device not found\n")); return; } m = &r->data.mouse; c = &raw_state.map[i].context; log_debug(("mouseb:rawinput: device:%d -> usFlags:%d,usButtonFlags:%d,ulRawButtons:%d,lLastX:%d,lLastY:%d,ulExtraInformation:%d\n", i, (unsigned)m->usFlags, (unsigned)m->usButtonFlags, (unsigned)m->ulRawButtons, (unsigned)m->lLastX, (unsigned)m->lLastY, (unsigned)m->ulExtraInformation)); if (m->usFlags & MOUSE_MOVE_ABSOLUTE) { /* absolute */ log_std(("WARNING:mouseb:rawinput: device:%d absolute move\n", i)); } else { /* relative */ c->x += m->lLastX; c->y += m->lLastY; } if (m->usButtonFlags & RI_MOUSE_WHEEL) { c->z += (SHORT)m->usButtonData; } if (m->usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) c->button |= 0x1; if (m->usButtonFlags & RI_MOUSE_BUTTON_1_UP) c->button &= ~0x1; if (m->usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) c->button |= 0x2; if (m->usButtonFlags & RI_MOUSE_BUTTON_2_UP) c->button &= ~0x2; if (m->usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) c->button |= 0x4; if (m->usButtonFlags & RI_MOUSE_BUTTON_3_UP) c->button &= ~0x4; if (m->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) c->button |= 0x8; if (m->usButtonFlags & RI_MOUSE_BUTTON_4_UP) c->button &= ~0x8; if (m->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) c->button |= 0x10; if (m->usButtonFlags & RI_MOUSE_BUTTON_5_UP) c->button &= ~0x10; log_debug(("mouseb:rawinput: id:%d,x:%d,y:%d,z:%d,button:%d\n", i, c->x, c->y, c->z, c->button)); }
void mouseb_rawinput_done(void) { log_std(("mouseb:rawinput: mouseb_rawinput_done()\n")); raw_state.mac = 0; }
static void video_frame_sync(struct advance_video_context* context) { double current; double expected; current = advance_timer(); if (context->state.sync_warming_up_flag) { /* syncronize the first time */ if (context->state.vsync_flag) { video_wait_vsync(); current = advance_timer(); } context->state.sync_pivot = 0; context->state.sync_last = current; context->state.sync_skip_counter = 0; context->state.sync_warming_up_flag = 0; log_debug(("advance:sync: throttle warming up\n")); } else { double time_before_sync, time_after_delay, time_after_sync; time_before_sync = current; expected = context->state.sync_last + context->state.skip_step * (1 + context->state.sync_skip_counter); context->state.sync_skip_counter = 0; /* take only a part of the error, this increase the stability */ context->state.sync_pivot *= 0.99; /* adjust with the previous error */ expected += context->state.sync_pivot; /* the vsync is used only if all the frames are displayed */ if ((video_flags() & MODE_FLAGS_RETRACE_WAIT_SYNC) != 0 && context->state.vsync_flag && context->state.skip_level_full == SYNC_MAX ) { /* wait until the retrace is near (3% early), otherwise if the */ /* mode has a double freq the retrace may be the wrong one. */ double early = 0.03 / video_measured_vclock(); if (current < expected - early) { current = video_frame_wait(current, expected - early); time_after_delay = current; if (current < expected) { double after; video_wait_vsync(); after = advance_timer(); if (after - current > 1.05 / (double)video_measured_vclock()) { log_std(("ERROR:emu:video: sync wait too long. %g instead of %g (max %g)\n", after - current, early, 1.0 / (double)video_measured_vclock())); } else if (after - current > 1.05 * early) { log_std(("WARNING:emu:video: sync wait too long. %g instead of %g (max %g)\n", after - current, early, 1.0 / (double)video_measured_vclock())); } /* if a sync complete correctly reset the error to 0 */ /* in this case the vsync is used for the correct clocking */ expected = after; current = after; } else { log_std(("ERROR:emu:video: sync delay too big\n")); } } else { log_std(("ERROR:emu:video: too late for a video sync\n")); current = video_frame_wait(current, expected); time_after_delay = current; } } else { current = video_frame_wait(current, expected); time_after_delay = current; } time_after_sync = current; /* update the error state */ context->state.sync_pivot = expected - current; if (fabs(context->state.sync_pivot) > context->state.skip_step / 50) log_std(("advance:sync: %.5f (err %6.1f%%) = %.5f + %.5f + %.5f < %.5f (compute + sleep + sync < max)\n", current - context->state.sync_last, context->state.sync_pivot * 100 / context->state.skip_step, time_before_sync - context->state.sync_last, time_after_delay - time_before_sync, time_after_sync - time_after_delay, context->state.skip_step)); if (context->state.sync_pivot < - context->state.skip_step * 16) { /* if the error is too big (negative) the delay is unrecoverable */ /* generally it happen with a virtual terminal switch */ /* the best solution is to restart the sync computation */ advance_video_update_skip(context); advance_video_update_sync(context); } context->state.sync_last = current; } }
void inputb_none_disable(void) { log_std(("inputb:none: inputb_none_disable()\n")); }
static void fb_log(struct fb_fix_screeninfo* fix, struct fb_var_screeninfo* var) { if (fix) { log_std(("video:fb: fix info\n")); log_std(("video:fb: smem_start:%08xh, smem_len:%08xh\n", (unsigned)fix->smem_start, (unsigned)fix->smem_len)); log_std(("video:fb: mmio_start:%08xh, mmio_len:%08xh\n", (unsigned)fix->mmio_start, (unsigned)fix->mmio_len)); log_std(("video:fb: type:%d, type_aux:%d\n", (unsigned)fix->type, (unsigned)fix->type_aux)); switch (fix->visual) { case FB_VISUAL_TRUECOLOR : log_std(("video:fb: visual:%d FB_VISUAL_TRUECOLOR\n", (unsigned)fix->visual)); break; case FB_VISUAL_PSEUDOCOLOR : log_std(("video:fb: visual:%d FB_VISUAL_PSEUDOCOLOR\n", (unsigned)fix->visual)); break; case FB_VISUAL_DIRECTCOLOR : log_std(("video:fb: visual:%d FB_VISUAL_DIRECTCOLOR\n", (unsigned)fix->visual)); break; default: log_std(("video:fb: visual:%d\n", (unsigned)fix->visual)); break; } log_std(("video:fb: xpanstep:%d, ypanstep:%d, ywrapstep:%d\n", (unsigned)fix->xpanstep, (unsigned)fix->ypanstep, (unsigned)fix->ywrapstep)); log_std(("video:fb: line_length:%d\n", (unsigned)fix->line_length)); log_std(("video:fb: accel:%d\n", (unsigned)fix->accel)); } if (var) { unsigned clock; log_std(("video:fb: variable info\n")); log_std(("video:fb: xres:%d, yres:%d\n", (unsigned)var->xres, (unsigned)var->yres)); log_std(("video:fb: xres_virtual:%d, yres_virtual:%d\n", (unsigned)var->xres_virtual, (unsigned)var->yres_virtual)); log_std(("video:fb: xoffset:%d, yoffset:%d\n", (unsigned)var->xoffset, (unsigned)var->yoffset)); log_std(("video:fb: bits_per_pixel:%d, grayscale:%d\n", (unsigned)var->bits_per_pixel, (unsigned)var->grayscale)); log_std(("video:fb: red %d:%d green %d:%d blue %d:%d transp %d:%d\n", (unsigned)var->red.length, (unsigned)var->red.offset, (unsigned)var->green.length, (unsigned)var->green.offset, (unsigned)var->blue.length, (unsigned)var->blue.offset, (unsigned)var->transp.length, (unsigned)var->transp.offset )); log_std(("video:fb: nonstd:%d, activate:%xh\n", (unsigned)var->nonstd, (unsigned)var->activate)); log_std(("video:fb: height:%d, width:%d\n", var->height, var->width)); log_std(("video:fb: accel_flags:%d\n", var->accel_flags)); if (var->pixclock) clock = (unsigned)(1000000000000LL / var->pixclock); else clock = 0; log_std(("video:fb: pixclock:%d (%d Hz), left:%d, right:%d, upper:%d, lower:%d, hsync:%d, vsync:%d\n", (unsigned)var->pixclock, clock, (unsigned)var->left_margin, (unsigned)var->right_margin, (unsigned)var->upper_margin, (unsigned)var->lower_margin, (unsigned)var->hsync_len, (unsigned)var->vsync_len )); log_std(("video:fb: sync:%xh", (unsigned)var->sync)); if ((var->sync & FB_SYNC_HOR_HIGH_ACT) != 0) log_std((" phsync")); if ((var->sync & FB_SYNC_VERT_HIGH_ACT) != 0) log_std((" pvsync")); if ((var->sync & FB_SYNC_EXT) != 0) log_std((" external_sync")); if ((var->sync & FB_SYNC_COMP_HIGH_ACT) != 0) log_std((" composite_sync")); if ((var->sync & FB_SYNC_BROADCAST) != 0) log_std((" broadcast_sync")); if ((var->sync & FB_SYNC_ON_GREEN) != 0) log_std((" sync_on_green")); log_std(("\n")); log_std(("video:fb: vmode:%xh", (unsigned)var->vmode)); if (var->vmode & FB_VMODE_INTERLACED) log_std((" interlace")); if (var->vmode & FB_VMODE_DOUBLE) log_std((" doublescan")); log_std(("\n")); } }
int os_inner_init(const char* title) { const char* display; struct utsname uts; struct sigaction term_action; struct sigaction quit_action; struct sigaction hup_action; struct sigaction pipe_action; #ifdef USE_SDL SDL_version compiled; #endif unsigned char endian[4] = { 0x1, 0x2, 0x3, 0x4 }; uint32 endian_little = 0x04030201; uint32 endian_big = 0x01020304; log_std(("os: os_inner_init\n")); if (uname(&uts) != 0) { log_std(("ERROR:os: uname failed\n")); } else { log_std(("os: sys %s\n", uts.sysname)); log_std(("os: release %s\n", uts.release)); log_std(("os: version %s\n", uts.version)); log_std(("os: machine %s\n", uts.machine)); } #if HAVE_SYSCONF #ifdef _SC_CLK_TCK log_std(("os: sysconf(_SC_CLK_TCK) %ld\n", sysconf(_SC_CLK_TCK))); #endif #ifdef _SC_NPROCESSORS_CONF log_std(("os: sysconf(_SC_NPROCESSORS_CONF) %ld\n", sysconf(_SC_NPROCESSORS_CONF))); #endif #ifdef _SC_NPROCESSORS_ONLN log_std(("os: sysconf(_SC_NPROCESSORS_ONLN) %ld\n", sysconf(_SC_NPROCESSORS_ONLN))); #endif #ifdef _SC_PHYS_PAGES log_std(("os: sysconf(_SC_PHYS_PAGES) %ld\n", sysconf(_SC_PHYS_PAGES))); #endif #ifdef _SC_AVPHYS_PAGES log_std(("os: sysconf(_SC_AVPHYS_PAGES) %ld\n", sysconf(_SC_AVPHYS_PAGES))); #endif #ifdef _SC_CHAR_BIT log_std(("os: sysconf(_SC_CHAR_BIT) %ld\n", sysconf(_SC_CHAR_BIT))); #endif #ifdef _SC_LONG_BIT log_std(("os: sysconf(_SC_LONG_BIT) %ld\n", sysconf(_SC_LONG_BIT))); #endif #ifdef _SC_WORD_BIT log_std(("os: sysconf(_SC_WORD_BIT) %ld\n", sysconf(_SC_WORD_BIT))); #endif #endif #ifdef _POSIX_PRIORITY_SCHEDULING /* OSDEF Check for POSIX scheduling */ log_std(("os: scheduling available\n")); #else log_std(("os: scheduling NOT available\n")); #endif /* print the compiler version */ #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) /* OSDEF Detect compiler version */ #define COMPILER_RESOLVE(a) #a #define COMPILER(a, b, c) COMPILER_RESOLVE(a) "." COMPILER_RESOLVE(b) "." COMPILER_RESOLVE(c) log_std(("os: compiler GNU %s\n", COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__))); #else log_std(("os: compiler unknown\n")); #endif /* check for int size */ if (sizeof(uint8) != 1) { target_err("The program is compiled with invalid uint8 type.\n"); return -1; } if (sizeof(uint16) != 2) { target_err("The program is compiled with invalid uint16 type.\n"); return -1; } if (sizeof(uint32) != 4) { target_err("The program is compiled with invalid uint32 type.\n"); return -1; } if (sizeof(uint64) != 8) { target_err("The program is compiled with invalid uint64 type.\n"); return -1; } /* check for the endianess */ #ifdef USE_MSB log_std(("os: compiled big endian system\n")); if (memcmp(endian, &endian_big, 4) != 0) { target_err("The program is compiled as bigendian but system doesn't appear to be bigendian.\n"); return -1; } #endif #ifdef USE_LSB log_std(("os: compiled little endian system\n")); if (memcmp(endian, &endian_little, 4) != 0) { target_err("The program is compiled as littleendian but system doesn't appear to be littleendian.\n"); return -1; } #endif #ifdef USE_SMP /* check the thread support */ if (os_thread() != 0) { target_err("Error on the threading support.\n"); return -1; } #endif /* get DISPLAY environment variable */ display = getenv("DISPLAY"); if (display) log_std(("os: DISPLAY=%s\n", display)); else log_std(("os: DISPLAY undef\n")); /* probe the delay system */ os_delay(); if (!os_internal_wm_active()) { log_std(("os: save term\n")); if (tcgetattr(fileno(stdin), &OS.term) != 0) { log_std(("ERROR:os: error getting the tty state.\n")); OS.term_active = 0; } else { OS.term_active = 1; } } #if defined(USE_X) OS.x_active = 0; { int event_base, error_base; int major_version, minor_version; log_std(("os: XOpenDisplay()\n")); OS.dga_display = XOpenDisplay(0); if (OS.dga_display) { OS.x_active = 1; } else { log_std(("WARNING:os: XOpenDisplay() failed. All the X drivers will be disabled.\n")); } } #endif #if defined(USE_SVGALIB) OS.svgalib_active = 0; if (!os_internal_wm_active()) { int h; log_std(("os: open /dev/svga\n")); /* try opening the device, otherwise vga_init() will abort the program. */ h = open("/dev/svga", O_RDWR); if (h >= 0) { int res; close(h); vga_disabledriverreport(); /* check the version of the SVGALIB */ res = vga_setmode(-1); if (res < 0 || res < 0x1911) { /* 1.9.11 */ log_std(("WARNING:os: invalid SVGALIB version %x. All the SVGALIB drivers will be disabled.\n", (int)res)); /* don't print the message. It may be a normal condition. */ /* target_nfo("Invalid SVGALIB version, you need SVGALIB version 1.9.x or 2.0.x.\nPlease upgrade or recompile without SVGALIB support.\n"); */ } else { log_std(("os: vga_init()\n")); if (vga_init() != 0) { log_std(("os: vga_init() failed\n")); target_err("Error initializing the SVGALIB video support.\n"); return -1; } OS.svgalib_active = 1; } } else { log_std(("WARNING:os: open /dev/svga failed. All the SVGALIB drivers will be disabled.\n")); /* don't print the message. It may be a normal condition. */ /* target_nfo("Error opening the SVGALIB device /dev/svga.\n"); */ } } else { log_std(("WARNING:os: vga_init() skipped because X is active. All the SVGALIB drivers will be disabled.\n")); /* don't print the message. It may be a normal condition. */ /* target_nfo("SVGALIB not initialized because it's unusable in X.\n"); */ } #endif #if defined(USE_SDL) log_std(("os: SDL_Init(SDL_INIT_NOPARACHUTE)\n")); if (SDL_Init(SDL_INIT_NOPARACHUTE) != 0) { log_std(("os: SDL_Init() failed, %s\n", SDL_GetError())); target_err("Error initializing the SDL video support.\n"); return -1; } OS.sdl_active = 1; SDL_VERSION(&compiled); log_std(("os: compiled with sdl %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch)); log_std(("os: linked with sdl %d.%d.%d\n", SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch)); #ifdef USE_MSB if (SDL_BYTEORDER != SDL_BIG_ENDIAN) { target_err("Invalid SDL endianess.\n"); return -1; } #endif #ifdef USE_LSB if (SDL_BYTEORDER != SDL_LIL_ENDIAN) { target_err("Invalid SDL endianess.\n"); return -1; } #endif #endif #if defined(USE_SLANG) OS.slang_active = 0; if (!os_internal_wm_active()) { log_std(("os: SLtt_get_terminfo()\n")); SLtt_get_terminfo(); log_std(("os: SLsmg_init_smg()\n")); SLsmg_init_smg(); OS.slang_active = 1; } else { log_std(("WARNING:os: SLang_init_tty() skipped because X is active. All the SLang drivers will be disabled.\n")); } #endif #if defined(USE_CURSES) OS.curses_active = 0; if (!os_internal_wm_active()) { log_std(("os: initscr()\n")); initscr(); start_color(); cbreak(); noecho(); nonl(); OS.curses_active = 1; } else { log_std(("WARNING:os: curses initscr() skipped because X is active. All the curses drivers will be disabled.\n")); } #endif /* set the titlebar */ sncpy(OS.title_buffer, sizeof(OS.title_buffer), title); /* set some signal handlers */ /* STANDARD signals */ term_action.sa_handler = (void (*)(int))os_signal; /* block external generated signals in the signal handler */ sigemptyset(&term_action.sa_mask); sigaddset(&term_action.sa_mask, SIGALRM); sigaddset(&term_action.sa_mask, SIGINT); sigaddset(&term_action.sa_mask, SIGTERM); sigaddset(&term_action.sa_mask, SIGHUP); sigaddset(&term_action.sa_mask, SIGQUIT); term_action.sa_flags = SA_RESTART | SA_SIGINFO; /* external generated */ sigaction(SIGALRM, &term_action, 0); sigaction(SIGINT, &term_action, 0); sigaction(SIGTERM, &term_action, 0); /* internal generated */ sigaction(SIGABRT, &term_action, 0); sigaction(SIGFPE, &term_action, 0); sigaction(SIGILL, &term_action, 0); sigaction(SIGSEGV, &term_action, 0); sigaction(SIGBUS, &term_action, 0); /* HUP signal */ hup_action.sa_handler = os_hup_signal; sigemptyset(&hup_action.sa_mask); hup_action.sa_flags = SA_RESTART; sigaction(SIGHUP, &hup_action, 0); /* QUIT signal */ quit_action.sa_handler = os_quit_signal; sigemptyset(&quit_action.sa_mask); quit_action.sa_flags = SA_RESTART; sigaction(SIGQUIT, &quit_action, 0); /* PIPE signal, ignoring it force some functions to */ /* return with error. It happen for example on the LCD sockets. */ pipe_action.sa_handler = SIG_IGN; sigemptyset(&pipe_action.sa_mask); pipe_action.sa_flags = SA_RESTART; sigaction(SIGPIPE, &pipe_action, 0); return 0; }
static adv_error fb_detect(void) { struct fb_var_screeninfo var; /* test bit depth */ log_std(("video:fb: test bits depths\n")); if (fb_test(&var, 25175200, 640, 656, 752, 800, 480, 490, 492, 525, 0, 0, 1, 1, MODE_FLAGS_INDEX_PALETTE8) != 0 || (var.bits_per_pixel != 8)) { log_std(("video:fb: disable palette8 bits modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_MODE_PALETTE8; } if (fb_test(&var, 25175200, 640, 656, 752, 800, 480, 490, 492, 525, 0, 0, 1, 1, MODE_FLAGS_INDEX_BGR15) != 0 || (var.bits_per_pixel != 16 || var.green.length != 5)) { log_std(("video:fb: disable bgr15 bits modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_MODE_BGR15; } if (fb_test(&var, 25175200, 640, 656, 752, 800, 480, 490, 492, 525, 0, 0, 1, 1, MODE_FLAGS_INDEX_BGR16) != 0 || (var.bits_per_pixel != 16 || var.green.length != 6)) { log_std(("video:fb: disable bgr16 bits modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_MODE_BGR16; } if (fb_test(&var, 25175200, 640, 656, 752, 800, 480, 490, 492, 525, 0, 0, 1, 1, MODE_FLAGS_INDEX_BGR24) != 0 || (var.bits_per_pixel != 24 || var.green.length != 8)) { log_std(("video:fb: disable bgr24 bits modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_MODE_BGR24; } if (fb_test(&var, 25175200, 640, 656, 752, 800, 480, 490, 492, 525, 0, 0, 1, 1, MODE_FLAGS_INDEX_BGR32) != 0 || (var.bits_per_pixel != 32 || var.green.length != 8)) { log_std(("video:fb: disable bgr32 bits modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_MODE_BGR32; } /* test interlace modes */ log_std(("video:fb: test interlace modes\n")); if (fb_test_auto(&var, 40280300, 1024, 1048, 1200, 1280, 768, 784, 787, 840, 0, 1, 1, 1) != 0 || (var.vmode & FB_VMODE_INTERLACED) == 0) { log_std(("video:fb: disable interlaced modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_PROGRAMMABLE_INTERLACE; } if (strstr(fb_state.fixinfo.id, "GeForce")!=0) { log_std(("video:fb: disable interlaced modes, not supported by the GeForce hardware\n")); /* the GeForce hardware doesn't support interlace */ fb_state.flags &= ~VIDEO_DRIVER_FLAGS_PROGRAMMABLE_INTERLACE; } /* test doublescan modes */ log_std(("video:fb: test doublescan modes\n")); if (fb_test_auto(&var, 12676000, 320, 328, 376, 400, 240, 245, 246, 262, 1, 0, 1, 1) != 0 || (var.vmode & FB_VMODE_DOUBLE) == 0) { log_std(("video:fb: disable doublescan modes, not supported\n")); fb_state.flags &= ~VIDEO_DRIVER_FLAGS_PROGRAMMABLE_DOUBLESCAN; } if (strstr(fb_state.fixinfo.id, "nVidia")!=0) { log_std(("video:fb: disable doublescan modes, not supported by the nVidia driver\n")); /* the Linux 2.4.20/2.4.21/2.4.22/2.4.23/2.4.24/2.4.25 driver doesn't support doublescan */ fb_state.flags &= ~VIDEO_DRIVER_FLAGS_PROGRAMMABLE_DOUBLESCAN; } return 0; }
void joystickb_lgallegro_done(void) { log_std(("joystickb:lgallegro: joystickb_lgallegro_done()\n")); remove_joystick(); }
adv_error fb_init(int device_id, adv_output output, unsigned overlay_size, adv_cursor cursor) { const char* fb; char id_buffer[64]; char* term; (void)cursor; (void)overlay_size; assert(!fb_is_active()); log_std(("video:fb: fb_init()\n")); if (sizeof(fb_video_mode) > MODE_DRIVER_MODE_SIZE_MAX) return -1; if (os_internal_wm_active()) { error_set("Unsupported in X. Try with the SDL library.\n"); return -1; } term = getenv("TERM"); if (!term || strcmp(term, "linux")!=0) { error_set("Works only with TERM=linux terminals.\n"); return -1; } if (output != adv_output_auto && output != adv_output_fullscreen) { error_set("Only fullscreen output is supported.\n"); return -1; } fb = getenv("FRAMEBUFFER"); if (fb && fb[0]) { fb_state.fd = open(fb, O_RDWR); } else { fb = "/dev/fb0"; fb_state.fd = open(fb, O_RDWR); if (fb_state.fd < 0 && errno == ENOENT) { fb = "/dev/fb/0"; fb_state.fd = open(fb, O_RDWR); } } if (fb_state.fd < 0) { if (errno == ENODEV) { error_set("Video board not supported. Error %d (%s).\n", errno, strerror(errno)); } else { error_set("Error opening the frame buffer %s. Error %d (%s).\n", fb, errno, strerror(errno)); } return -1; } /* get the fixed info */ if (fb_getfix(&fb_state.fixinfo) != 0) { error_set("Error getting the fixed video mode information.\n"); goto err_close; } /* get the variable info */ if (fb_getvar(&fb_state.varinfo, 0) != 0) { error_set("Error getting the variable video mode information.\n"); goto err_close; } /* copy the id in a safe way, it may be not 0 terminated */ sncpyn(id_buffer, sizeof(id_buffer), fb_state.fixinfo.id, sizeof(fb_state.fixinfo.id)); log_std(("video:fb: id %s\n", id_buffer)); fb_log(&fb_state.fixinfo, &fb_state.varinfo); if (strcmp(id_buffer, "VESA VGA")==0) { error_set("The 'vesafb' FrameBuffer driver doesn't allow the creation of new video modes.\n"); goto err_close; } fb_state.flags = VIDEO_DRIVER_FLAGS_MODE_PALETTE8 | VIDEO_DRIVER_FLAGS_MODE_BGR15 | VIDEO_DRIVER_FLAGS_MODE_BGR16 | VIDEO_DRIVER_FLAGS_MODE_BGR24 | VIDEO_DRIVER_FLAGS_MODE_BGR32 | VIDEO_DRIVER_FLAGS_PROGRAMMABLE_ALL | VIDEO_DRIVER_FLAGS_OUTPUT_FULLSCREEN; if (fb_detect() != 0) { goto err_close; } if ((fb_state.flags & (VIDEO_DRIVER_FLAGS_MODE_PALETTE8 | VIDEO_DRIVER_FLAGS_MODE_BGR15 | VIDEO_DRIVER_FLAGS_MODE_BGR16 | VIDEO_DRIVER_FLAGS_MODE_BGR24 | VIDEO_DRIVER_FLAGS_MODE_BGR32)) == 0) { error_set("This '%s' FrameBuffer driver doesn't seem to allow the creation of new video modes.\n", id_buffer); goto err_close; } fb_state.active = 1; return 0; err_close: close(fb_state.fd); return -1; }
int main(int argc, const char **argv) { static const char *null_action_argv[] = {NULL}; static struct poptOption popt_help_options[] = { { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL }, { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL }, { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL }, POPT_TABLEEND }; static struct poptOption popt_options[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL }, { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL }, { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL }, { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL }, { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL }, { "progress-frequency", '\0', POPT_ARG_INT, &opt_progress_frequency, 0, N_("Progress line update (in seconds)"), N_("secs") }, { "no-wipe", '\0', POPT_ARG_NONE, &opt_no_wipe, 0, N_("Do not wipe device after format"), NULL }, { "data-device", '\0', POPT_ARG_STRING, &opt_data_device, 0, N_("Path to data device (if separated)"), N_("path") }, { "journal-size", 'j', POPT_ARG_STRING,&opt_journal_size_str, 0, N_("Journal size"), N_("bytes") }, { "interleave-sectors", '\0', POPT_ARG_INT, &opt_interleave_sectors, 0, N_("Interleave sectors"), N_("SECTORS") }, { "journal-watermark", '\0', POPT_ARG_INT, &opt_journal_watermark, 0, N_("Journal watermark"),N_("percent") }, { "journal-commit-time",'\0', POPT_ARG_INT, &opt_journal_commit_time,0, N_("Journal commit time"), N_("ms") }, { "bitmap-sectors-per-bit",'\0', POPT_ARG_INT,&opt_bitmap_sectors_per_bit, 0, N_("Number of 512-byte sectors per bit (bitmap mode)."), NULL }, { "bitmap-flush-time", '\0', POPT_ARG_INT, &opt_bitmap_flush_time, 0, N_("Bitmap mode flush time"), N_("ms") }, { "tag-size", 't', POPT_ARG_INT, &opt_tag_size, 0, N_("Tag size (per-sector)"), N_("bytes") }, { "sector-size", 's', POPT_ARG_INT, &opt_sector_size, 0, N_("Sector size"), N_("bytes") }, { "buffer-sectors", '\0', POPT_ARG_INT, &opt_buffer_sectors, 0, N_("Buffers size"), N_("SECTORS") }, { "integrity", 'I', POPT_ARG_STRING, &opt_integrity, 0, N_("Data integrity algorithm"), NULL }, { "integrity-key-size", '\0', POPT_ARG_INT, &opt_integrity_key_size, 0, N_("The size of the data integrity key"), N_("BITS") }, { "integrity-key-file", '\0', POPT_ARG_STRING, &opt_integrity_key_file, 0, N_("Read the integrity key from a file"), NULL }, { "journal-integrity", '\0', POPT_ARG_STRING, &opt_journal_integrity, 0, N_("Journal integrity algorithm"), NULL }, { "journal-integrity-key-size",'\0', POPT_ARG_INT, &opt_journal_integrity_key_size,0, N_("The size of the journal integrity key"), N_("BITS") }, { "journal-integrity-key-file",'\0', POPT_ARG_STRING, &opt_journal_integrity_key_file,0, N_("Read the journal integrity key from a file"), NULL }, { "journal-crypt", '\0', POPT_ARG_STRING, &opt_journal_crypt, 0, N_("Journal encryption algorithm"), NULL }, { "journal-crypt-key-size", '\0', POPT_ARG_INT, &opt_journal_crypt_key_size, 0, N_("The size of the journal encryption key"), N_("BITS") }, { "journal-crypt-key-file", '\0', POPT_ARG_STRING, &opt_journal_crypt_key_file, 0, N_("Read the journal encryption key from a file"), NULL }, { "integrity-no-journal", 'D', POPT_ARG_NONE, &opt_integrity_nojournal, 0, N_("Disable journal for integrity device"), NULL }, { "integrity-recovery-mode", 'R', POPT_ARG_NONE, &opt_integrity_recovery, 0, N_("Recovery mode (no journal, no tag checking)"), NULL }, { "integrity-bitmap-mode", 'B', POPT_ARG_NONE, &opt_integrity_bitmap, 0, N_("Use bitmap to track changes and disable journal for integrity device"), NULL }, { "integrity-recalculate", '\0', POPT_ARG_NONE, &opt_integrity_recalculate, 0, N_("Recalculate initial tags automatically."), NULL }, POPT_TABLEEND }; poptContext popt_context; struct action_type *action; const char *aname; int r; crypt_set_log_callback(NULL, tool_log, NULL); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); popt_context = poptGetContext("integrity", argc, argv, popt_options, 0); poptSetOtherOptionHelp(popt_context, _("[OPTION...] <action> <action-specific>")); while ((r = poptGetNextOpt(popt_context)) >= 0) { } if (r < -1) usage(popt_context, EXIT_FAILURE, poptStrerror(r), poptBadOption(popt_context, POPT_BADOPTION_NOALIAS)); if (opt_version_mode) { log_std("%s %s\n", PACKAGE_INTEGRITY, PACKAGE_VERSION); poptFreeContext(popt_context); exit(EXIT_SUCCESS); } if (!(aname = poptGetArg(popt_context))) usage(popt_context, EXIT_FAILURE, _("Argument <action> missing."), poptGetInvocationName(popt_context)); action_argc = 0; action_argv = poptGetArgs(popt_context); /* Make return values of poptGetArgs more consistent in case of remaining argc = 0 */ if (!action_argv) action_argv = null_action_argv; /* Count args, somewhat unnice, change? */ while (action_argv[action_argc] != NULL) action_argc++; /* Handle aliases */ if (!strcmp(aname, "create") && action_argc > 1) { /* create command had historically switched arguments */ if (action_argv[0] && action_argv[1]) { const char *tmp = action_argv[0]; action_argv[0] = action_argv[1]; action_argv[1] = tmp; } aname = "open"; } else if (!strcmp(aname, "remove")) { aname = "close"; } for (action = action_types; action->type; action++) if (strcmp(action->type, aname) == 0) break; if (!action->type) usage(popt_context, EXIT_FAILURE, _("Unknown action."), poptGetInvocationName(popt_context)); if (action_argc < action->required_action_argc) { char buf[128]; snprintf(buf, 128,_("%s: requires %s as arguments"), action->type, action->arg_desc); usage(popt_context, EXIT_FAILURE, buf, poptGetInvocationName(popt_context)); } if (!strcmp(aname, "format") && opt_tag_size == 0) opt_tag_size = DEFAULT_TAG_SIZE; if (opt_integrity_recalculate && strcmp(aname, "open")) usage(popt_context, EXIT_FAILURE, _("Option --integrity-recalculate can be used only for open action."), poptGetInvocationName(popt_context)); if (opt_interleave_sectors < 0 || opt_journal_watermark < 0 || opt_journal_commit_time < 0 || opt_tag_size < 0 || opt_sector_size < 0 || opt_buffer_sectors < 0 || opt_integrity_key_size < 0 || opt_journal_integrity_key_size < 0 || opt_journal_crypt_key_size < 0 || opt_bitmap_flush_time < 0 || opt_bitmap_sectors_per_bit < 0) usage(popt_context, EXIT_FAILURE, _("Negative number for option not permitted."), poptGetInvocationName(popt_context)); if (strcmp(aname, "format") && (opt_journal_size_str || opt_interleave_sectors || opt_sector_size || opt_tag_size || opt_no_wipe )) usage(popt_context, EXIT_FAILURE, _("Options --journal-size, --interleave-sectors, --sector-size, --tag-size" " and --no-wipe can be used only for format action.\n"), poptGetInvocationName(popt_context)); if (opt_journal_size_str && tools_string_to_size(NULL, opt_journal_size_str, &opt_journal_size)) usage(popt_context, EXIT_FAILURE, _("Invalid journal size specification."), poptGetInvocationName(popt_context)); if ((opt_integrity_key_file && !opt_integrity_key_size) || (!opt_integrity_key_file && opt_integrity_key_size)) usage(popt_context, EXIT_FAILURE, _("Both key file and key size options must be specified."), poptGetInvocationName(popt_context)); if (!opt_integrity && opt_integrity_key_file) usage(popt_context, EXIT_FAILURE, _("Integrity algorithm must be specified if integrity key is used."), poptGetInvocationName(popt_context)); if ((opt_journal_integrity_key_file && !opt_journal_integrity_key_size) || (!opt_journal_integrity_key_file && opt_journal_integrity_key_size)) usage(popt_context, EXIT_FAILURE, _("Both journal integrity key file and key size options must be specified."), poptGetInvocationName(popt_context)); if (!opt_journal_integrity && opt_journal_integrity_key_file) usage(popt_context, EXIT_FAILURE, _("Journal integrity algorithm must be specified if journal integrity key is used."), poptGetInvocationName(popt_context)); if ((opt_journal_crypt_key_file && !opt_journal_crypt_key_size) || (!opt_journal_crypt_key_file && opt_journal_crypt_key_size)) usage(popt_context, EXIT_FAILURE, _("Both journal encryption key file and key size options must be specified."), poptGetInvocationName(popt_context)); if (!opt_journal_crypt && opt_journal_crypt_key_file) usage(popt_context, EXIT_FAILURE, _("Journal encryption algorithm must be specified if journal encryption key is used."), poptGetInvocationName(popt_context)); if (opt_integrity_recovery && opt_integrity_bitmap) usage(popt_context, EXIT_FAILURE, _("Recovery and bitmap mode options are mutually exclusive."), poptGetInvocationName(popt_context)); if (opt_integrity_bitmap && (opt_journal_integrity_key_file || opt_journal_crypt || opt_journal_watermark || opt_journal_commit_time)) usage(popt_context, EXIT_FAILURE, _("Journal options cannot be used in bitmap mode."), poptGetInvocationName(popt_context)); if (!opt_integrity_bitmap && (opt_bitmap_flush_time || opt_bitmap_sectors_per_bit)) usage(popt_context, EXIT_FAILURE, _("Bitmap options can be used only in bitmap mode."), poptGetInvocationName(popt_context)); if (opt_debug) { opt_verbose = 1; crypt_set_debug_level(-1); dbg_version_and_cmd(argc, argv); } r = run_action(action); poptFreeContext(popt_context); return r; }
static adv_error fb_setup_color(void) { /* set the color information in direct color modes */ if (fb_state.fixinfo.visual == FB_VISUAL_DIRECTCOLOR) { unsigned red_l = 1 << fb_state.varinfo.red.length; unsigned green_l = 1 << fb_state.varinfo.green.length; unsigned blue_l = 1 << fb_state.varinfo.blue.length; __u16* red_map; __u16* green_map; __u16* blue_map; __u16* trasp_map; unsigned l; struct fb_cmap cmap; unsigned i; l = red_l; if (l < green_l) l = green_l; if (l < blue_l) l = blue_l; log_std(("video:fb: set ramp %d:%d:%d %d\n", red_l, green_l, blue_l, l)); red_map = malloc(sizeof(__u16) * l); green_map = malloc(sizeof(__u16) * l); blue_map = malloc(sizeof(__u16) * l); trasp_map = malloc(sizeof(__u16) * l); for (i=0;i<l;++i) { if (i < red_l) red_map[i] = 65535 * i / (red_l-1); else red_map[i] = 65535; if (i < green_l) green_map[i] = 65535 * i / (green_l-1); else green_map[i] = 65535; if (i < blue_l) blue_map[i] = 65535 * i / (blue_l-1); else blue_map[i] = 65535; trasp_map[i] = 0; } log_std(("video:fb: limit ramp %d:%d:%d %d:%d:%d\n", (unsigned)red_map[0], (unsigned)green_map[0], (unsigned)blue_map[0], (unsigned)red_map[red_l - 1], (unsigned)green_map[green_l - 1], (unsigned)blue_map[blue_l - 1])); cmap.start = 0; cmap.len = l; cmap.red = red_map; cmap.green = green_map; cmap.blue = blue_map; cmap.transp = trasp_map; if (fb_setcmap(&cmap) != 0) { free(red_map); free(green_map); free(blue_map); free(trasp_map); return -1; } free(red_map); free(green_map); free(blue_map); free(trasp_map); } return 0; }
void joystickb_lgrawinput_done(void) { log_std(("joystickb:lgrawinput: joystickb_lgrawinput_done()\n")); raw_state.mac = 0; }
adv_error fb_mode_set(const fb_video_mode* mode) { unsigned req_xres; unsigned req_yres; unsigned req_bits_per_pixel; assert(fb_is_active() && !fb_mode_is_active()); log_std(("video:fb: fb_mode_set()\n")); log_std(("video:fb: get old\n")); /* get the current info */ if (fb_getvar(&fb_state.oldinfo, 0) != 0) { error_set("Error getting the variable video mode information.\n"); goto err; } fb_log(0, &fb_state.oldinfo); fb_preset(&fb_state.varinfo, mode->crtc.pixelclock, mode->crtc.hde, mode->crtc.hrs, mode->crtc.hre, mode->crtc.ht, mode->crtc.vde, mode->crtc.vrs, mode->crtc.vre, mode->crtc.vt, crtc_is_doublescan(&mode->crtc), crtc_is_interlace(&mode->crtc), crtc_is_nhsync(&mode->crtc), crtc_is_nvsync(&mode->crtc), mode->index, FB_ACTIVATE_NOW ); log_std(("video:fb: set new\n")); fb_log(0, &fb_state.varinfo); /* save the minimun required data */ req_xres = fb_state.varinfo.xres; req_yres = fb_state.varinfo.yres; req_bits_per_pixel = fb_state.varinfo.bits_per_pixel; /* set the mode */ if (fb_setvar(&fb_state.varinfo) != 0) { error_set("Error setting the variable video mode information.\n"); goto err; } log_std(("video:fb: get new\n")); /* get the fixed info */ if (fb_getfix(&fb_state.fixinfo) != 0) { error_set("Error getting the fixed video mode information.\n"); goto err_restore; } /* get the variable info */ if (fb_getvar(&fb_state.varinfo, mode->index) != 0) { error_set("Error getting the variable video mode information.\n"); goto err_restore; } fb_state.freq = fb_state.varinfo.pixclock; fb_state.freq *= fb_state.varinfo.xres + fb_state.varinfo.left_margin + fb_state.varinfo.right_margin + fb_state.varinfo.hsync_len; fb_state.freq *= fb_state.varinfo.yres + fb_state.varinfo.upper_margin + fb_state.varinfo.lower_margin + fb_state.varinfo.vsync_len; if (fb_state.freq != 0) { fb_state.freq = 1000000000000LL / fb_state.freq; } log_std(("video:fb: frequency %g\n", fb_state.freq)); fb_log(&fb_state.fixinfo, &fb_state.varinfo); /* check the validity of the resulting video mode */ if (req_xres > fb_state.varinfo.xres || req_yres > fb_state.varinfo.yres || req_bits_per_pixel != fb_state.varinfo.bits_per_pixel ) { log_std(("ERROR:video:fb: request for mode %dx%d %d bits resulted in mode %dx%dx %d bits\n", req_xres, req_yres, req_bits_per_pixel, fb_state.varinfo.xres, fb_state.varinfo.yres, fb_state.varinfo.bits_per_pixel)); error_set("Error setting the requested video mode.\n"); goto err_restore; } if (req_xres != fb_state.varinfo.xres || req_yres != fb_state.varinfo.yres ) { /* allow bigger modes */ log_std(("WARNING:video:fb: request for mode %dx%d resulted in mode %dx%dx\n", req_xres, req_yres, fb_state.varinfo.xres, fb_state.varinfo.yres)); } if (fb_setup_color() != 0) { error_set("Error setting the color information.\n"); goto err_restore; } fb_write_line = fb_linear_write_line; fb_state.bytes_per_pixel = (fb_state.varinfo.bits_per_pixel + 7) / 8; fb_state.bytes_per_scanline = fb_state.fixinfo.line_length; fb_state.index = mode->index; fb_state.ptr = mmap(0, fb_state.fixinfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb_state.fd, 0 ); if (fb_state.ptr == MAP_FAILED) { error_set("Error mapping the video memory.\n"); goto err_restore; } fb_state.wait_last = 0; fb_state.wait = fb_wait_detect; /* reset the wait mode */ fb_state.wait_error = 0; fb_state.mode_active = 1; return 0; err_restore: fb_setvar(&fb_state.oldinfo); /* ignore error */ err: return -1; }
adv_error joystickb_raw_init(int joystickb_id) { unsigned i; adv_bool eacces = 0; log_std(("josytickb:raw: joystickb_raw_init(id:%d)\n", joystickb_id)); log_std(("joystickb:raw: opening joystick from 0 to %d\n", RAW_JOYSTICK_DEVICE_MAX)); raw_state.mac = 0; for (i = 0; i < RAW_JOYSTICK_DEVICE_MAX; ++i) { int f; int version; char file[128]; if (raw_state.mac >= RAW_JOYSTICK_MAX) continue; snprintf(file, sizeof(file), "/dev/js%d", i); f = open(file, O_RDONLY | O_NONBLOCK); if (f == -1) { if (errno != ENODEV) { log_std(("joystickb:raw: error opening device %s, errno %d (%s)\n", file, errno, strerror(errno))); } if (errno == EACCES) { eacces = 1; } snprintf(file, sizeof(file), "/dev/input/js%d", i); f = open(file, O_RDONLY | O_NONBLOCK); } if (f == -1) { if (errno != ENODEV) { log_std(("joystickb:raw: error opening device %s, errno %d (%s)\n", file, errno, strerror(errno))); } continue; } log_std(("joystickb:raw: open device %s\n", file)); if (ioctl(f, JSIOCGVERSION, &version) < 0) { log_std(("ERROR:joystickb:raw: ioctl(JSIOCVERSION) failed\n")); close(f); continue; } joystickb_log(f); if (joystickb_setup(&raw_state.map[raw_state.mac], f) != 0) { close(f); continue; } ++raw_state.mac; } if (!raw_state.mac) { if (eacces) error_set("No joystick found. Check the /dev/js* and /dev/input/js* permissions.\n"); else error_set("No joystick found.\n"); return -1; } return 0; }
adv_error inputb_none_init(int inputb_id) { log_std(("inputb:none: inputb_none_init(id:%d)\n", inputb_id)); return 0; }
/* * \brief function to parse CONNECT packet arguments * \param argc Number of arguments. * \param argv Arguments. * \param pkt Pointer to packet. */ umqtt_ret build_connect_pkt_getopts(int argc, char **argv, struct mqtt_packet *pkt) { int ret = UMQTT_SUCCESS; int c, option_index = 0; char username[1024] = "\0"; char password[1024] = "\0"; char will_topic[MAX_TOPIC_LEN] = "\0"; char will_msg[1024] = "\0"; char clientid[MQTT_CLIENTID_MAX_LEN] = "\0"; static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, {"verbose", required_argument, 0, 'v'}, {"clientid", required_argument, 0, 'c'}, {"proto", required_argument, 0, 'p'}, {"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'P'}, {"clean-session", no_argument, 0, 's'}, {"retain", no_argument, 0, 'r'}, {"qos", required_argument, 0, 'q'}, {"topic", required_argument, 0, 't'}, {"message", required_argument, 0, 'm'}, {"keepalive", required_argument, 0, 'k'}, {0, 0, 0, 0} }; /* get arguments */ while (1) { if ((c = getopt_long(argc, argv, "hv:u:P:sc:p:rq:t:m:k:", long_options, &option_index)) != -1) { switch (c) { case 'h': print_usage(); ret = UMQTT_ERROR; goto end; case 'v': /* set log level */ if (optarg) { set_log_level_str(optarg); } break; case 'c': /* Set clientid */ if (optarg) { strcpy(clientid, optarg); } else { log_std(LOG_ERROR, "The clientid flag should be followed by a clientid"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'p': /* set protocol level - this only changes the value */ if (optarg) { pkt->variable->connect.proto_level = (0x0f & (uint8_t)atoi(optarg)); } break; case 'u': /* Set username */ if (optarg) { strcpy(username, optarg); /* set username flag */ pkt->variable->connect.flags.user_flag = 1; } else { log_std(LOG_ERROR, "The username flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'P': /* Set password */ if (optarg) { strcpy(password, optarg); /* set password flag */ pkt->variable->connect.flags.pass_flag = 1; } else { log_std(LOG_ERROR, "The password flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 's': /* set clean session flag */ pkt->variable->connect.flags.clean_session_flag = 1; break; case 't': /* Set will topic */ if (optarg) { strcpy(will_topic, optarg); /* set will flag */ pkt->variable->connect.flags.will_flag = 1; } else { log_std(LOG_ERROR, "The will topic flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'm': /* set the will message */ if (optarg) { strcpy(will_msg, optarg); /* set will flag */ pkt->variable->connect.flags.will_flag = 1; } else { log_std(LOG_ERROR, "The will message flag should be followed by a message"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'r': /* set retain flag */ pkt->variable->connect.flags.will_retain_flag = 1; /* set will flag */ pkt->variable->connect.flags.will_flag = 1; break; case 'q': /* set the will QoS */ if (optarg) { pkt->variable->connect.flags.will_qos = (0x03 & (uint8_t)atoi(optarg)); /* set will flag */ pkt->variable->connect.flags.will_flag = 1; } else { log_std(LOG_ERROR, "The will Qos flag should be followed by a QoS (0-3)"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'k': /* Set keep alive */ if (optarg) { pkt->variable->connect.keep_alive = (uint16_t)atoi(optarg); } else { log_std(LOG_ERROR, "The will topic flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } } } else { /* Final arguement */ break; } } if (clientid[0] == '\0') { log_std(LOG_INFO, "Automatically generating a clientID since none was specified"); } if (pkt->variable->connect.flags.will_flag == 1) { if (will_topic[0] == '\0') { log_std(LOG_INFO, "A will topic must be specified when the will flag is set"); ret = UMQTT_ERROR; goto end; } if (will_msg[0] == '\0') { log_std(LOG_INFO, "A will message must be specified when the will flag is set"); ret = UMQTT_ERROR; goto end; } } ret = init_packet_payload(pkt, pkt->fixed->generic.type, NULL, 0); if (ret) { /* error */ goto end; } /* CONNECT payload non optional, overide defaults */ ret = set_connect_payload(pkt, clientid, username, password, will_topic, will_msg); end: return ret; }
adv_error inputb_none_enable(adv_bool graphics) { log_std(("inputb:none: inputb_none_enable(graphics:%d)\n", (int)graphics)); return 0; }
/* * \brief function to parse SUBSCRIBE and UNSUBSCRIBE packet arguments * \param argc Number of arguments. * \param argv Arguments. * \param pkt Pointer to packet. */ umqtt_ret build_un_subscribe_pkt_getopts(int argc, char **argv, struct mqtt_packet *pkt) { int ret = UMQTT_SUCCESS; int c, option_index = 0; uint16_t pkt_id = 1; uint8_t payload[MAX_MSG_LEN] = "\0"; size_t pay_len = 0; static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, {"verbose", required_argument, 0, 'v'}, {"topic", required_argument, 0, 't'}, {"qos", required_argument, 0, 'q'}, {"pkt-id", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* get arguments */ while (1) { if ((c = getopt_long(argc, argv, "hv:t:q:p:", long_options, &option_index)) != -1) { switch (c) { case 'h': print_usage(); ret = UMQTT_ERROR; goto end; case 'v': /* set log level */ if (optarg) { set_log_level_str(optarg); } break; case 't': /* Set topic */ if (optarg) { pay_len += encode_utf8_string((struct utf8_enc_str *)&payload[pay_len], optarg, strlen(optarg)); if (pkt->fixed->generic.type == SUBSCRIBE) { /* QoS flag */ pay_len += sizeof(uint8_t); } } else { log_std(LOG_ERROR, "The topic flag should be followed by a topic"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'q': /* set the QoS */ if (pkt->fixed->generic.type == SUBSCRIBE) { if (optarg) { payload[pay_len - 1] = (0x03 & (uint8_t)atoi(optarg)); } else { log_std(LOG_ERROR, "The QoS flag should be followed by a QoS (0-3)"); print_usage(); ret = UMQTT_ERROR; goto end; } } else { /* UNSUBSCRIBE */ log_std(LOG_ERROR, "The QoS flag has no effect with the UNSUBSCRIBE packet type"); print_usage(); ret = UMQTT_ERROR; goto end; } break; case 'p': /* Set Packet Identifier */ if (optarg) { pkt_id = (uint16_t)atoi(optarg); generate_packet_id(pkt_id); } else { log_std(LOG_ERROR, "The packet identifier flag should be followed by a packet id"); print_usage(); ret = UMQTT_ERROR; goto end; } break; } } else { /* Final arguement */ break; } } /* set subscribe variable header and message payload */ ret = init_packet_variable_header(pkt, pkt->fixed->generic.type); if (ret) { log_std(LOG_ERROR, "Failed to assign packet variable header"); goto end; } ret = init_packet_payload(pkt, SUBSCRIBE, (uint8_t *)&payload, pay_len); if (ret) { log_std(LOG_ERROR, "Failed to assign SUBSCRIBE packet payload"); goto end; } end: return ret; }
int test_packet_creation() { ctrl_pkt_type type; int delta = 0, fails = 0; struct mqtt_packet *ctrl_pkt, *gen_pkt; log_std(LOG_INFO, "Testing packet creation:"); /* CONNECT packet */ type = CONNECT; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, 0, 0); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); /* PUBLISH packet */ type = PUBLISH; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, (uint8_t *)"uMQTT test PUBLISH packet", sizeof("uMQTT test PUBLISH packet")); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); /* SUBSCRIBE packet */ type = SUBSCRIBE; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, 0, 0); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); /* PINGREQ packet */ type = PINGREQ; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, 0, 0); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); /* PINGRESP packet */ type = PINGRESP; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, 0, 0); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); /* DISCONNECT packet */ type = DISCONNECT; ctrl_pkt = create_manual_control_pkt(type); gen_pkt = construct_default_packet(type, 0, 0); finalise_packet(gen_pkt); delta = test_compare_packets(ctrl_pkt, gen_pkt); if (delta) { fails++; log_std(LOG_INFO, "Creation of control packet type %d failed.", (int)type); } free_packet(ctrl_pkt); free_packet(gen_pkt); if (!fails) { log_std(LOG_INFO, "Control packet creation successful for all packet types"); } return fails; }