static void write_byte(cfg_addr_t pos, uint8_t b) { DBG_C(' '); DBG_X(pos); DBG_C('='); DBG_X(b); eeprom_update_byte((uint8_t *)EEPROM_POS + pos, b); }
static dps_param_t handle_get_file_id(dps_appctx_t appctx, ptp_obj_handle_t autprint_mrk_file_id, char *dcf_file_path, ptp_obj_handle_t *id) { jint_t i; char *filename = NULL; dps_param_t rc; DECLARE_FNAME("handle_get_file_id"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); *id = 0; rc = DPS_PARAM_MAKE(DPS_RESULT_UNSUPPORTED_OP, DPS_RESULT_MIN_INVALID_VALUE); for (i=0; sample_image[i].image; i++) { if (!sample_image[i].name) continue; filename = j_strdup(sample_image[i].name); if (!filename) { DBG_E(DSLAVE_DPS_API, ("%s: error allocating memory (strdup)\n", fname)); rc = DPS_RESULT_UNEXECUTED_OP; goto Exit; } to_upper(filename); /* TODO: The code that should be implemented here is not a * straightforward string comparison. * The dcf_file_path is the image's path relative * to the DPOF file. In a real system e.g, the image'ss full path * would be reconstructed in order to do a full path search * for the file */ if (!j_strcmp(dcf_file_path+sizeof(DCF_PREFIX)-1, filename)) { jfree(filename); break; } jfree(filename); } if (sample_image[i].image) { *id = sample_image[0].id; rc = DPS_RESULT_OK; } DBG_X(DSLAVE_DPS_API, ("%s: autprint_id: 0x%X filename: %s" " img_id: 0x%X\n", fname, autprint_mrk_file_id, dcf_file_path, *id)); Exit: return rc; }
static jresult_t cdc_start_data_xfer(uwh_cdc_dev_h dev_ctx, void *membuf, juint32_t size, cdc_general_data_cb_t cb, uwh_cdc_app_h app_ctx, void *app_priv, cdc_req_type type) { jresult_t rc = JENOMEM; usbd_pipe_handle pipe; cdc_cmd_priv_t *priv; DECLARE_FNAME("cdc_start_data_xfer"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); priv = cdc_init_request_priv(GENERAL_CDC_SC(dev_ctx), type, app_ctx, app_priv); if (!priv) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed to allocate private handle\n", fname)); goto Error; } pipe = (type == SEND_DATA) ? priv->sc->bulk_pipe_out : priv->sc->bulk_pipe_in; priv->cdc_callback.data_cb = cb; rc = cdc_xfer_data_pipe(priv, pipe, membuf, size); Error: if (rc) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed\n", fname)); if (priv) cdc_uninit_request_priv(priv); } return rc; }
usb_descriptor_t *cdc_find_desc(usb_config_descriptor_t *conf_d, check_desc_func func, void *arg) { juint8_t length; juint8_t *desc_ptr, *end; usb_descriptor_t *desc = NULL; DECLARE_FNAME("cdc_find_desc"); desc_ptr = (juint8_t *)conf_d; desc = (usb_descriptor_t *)desc_ptr; end = desc_ptr + ua_le16toh(conf_d->wTotalLength); length = conf_d->bLength; DBG_X(DHOST_CDC_GENERAL, ("%s: Entered - desc_ptr %p, end %p\n", fname, desc_ptr, end)); while ((desc_ptr + length <= end) && length) { if (func(desc, arg)) goto Exit; /* Get the next interface descriptor */ desc_ptr += length; desc = (usb_descriptor_t *)desc_ptr; length = desc->bLength; } desc = NULL; DBG_V(DHOST_CDC_GENERAL, ("%s: Exiting. No descriptor match\n", fname)); Exit: return desc; }
static void config_complete(dps_appctx_t appctx, dps_param_t result, dps_res_conf_t *printer_cfg) { int i; dps_req_conf_t *cfg; DECLARE_FNAME("config_complete"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); if (!result || !printer_cfg) { DBG_E(DSLAVE_DPS_API, ("%s: failed to parse printer configuration (%d)" "\n", fname, result)); return; } DBG_I(DSLAVE_DPS_API, ("%s: result=%X\n", fname, result)); DBG_I(DSLAVE_DPS_API, ("%s: service_available=%X\n", fname, printer_cfg->service_available)); cfg = &printer_cfg->conf; DBG_I(DSLAVE_DPS_API, ("%s: version_count=%u\n", fname, cfg->versions_count)); for(i=0; i<cfg->versions_count; i++) { DBG_I(DSLAVE_DPS_API, ("%s: version=%d.%d\n", fname, cfg->dps_version[i].major, cfg->dps_version[i].minor)); } DBG_I(DSLAVE_DPS_API, ("%s: vendor_name=%s\n", fname, cfg->vendor_name)); DBG_I(DSLAVE_DPS_API, ("%s: ven_spec_ver=%d.%d\n", fname, cfg->vendor_specific_version.major, cfg->vendor_specific_version.minor)); DBG_I(DSLAVE_DPS_API, ("%s: product_name=%s\n", fname, cfg->product_name)); DBG_I(DSLAVE_DPS_API, ("%s: serial_no=%s\n", fname, cfg->serial_no)); }
static jint_t handle_printer_connect(dps_appctx_t appctx) { DECLARE_FNAME("handle_printer_connect"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); return 1; /* WE WANT PICTBRIDGE */ }
static dps_param_t handle_notify_job_status(dps_appctx_t appctx, dps_job_status_t *status) { DECLARE_FNAME("handle_notify_job_status"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); job_stat_complete(appctx, 0, status); return DPS_RESULT_OK; }
void do_command(u_char cmd) { if(cmd == C_READ_PIO) { DBG_P(":I"); do_read_pio(); } else { DBG_P("?CI"); DBG_X(cmd); set_idle(); } }
static dps_param_t handle_notify_device_status(dps_appctx_t appctx, dps_device_status_t *status) { DECLARE_FNAME("handle_notify_device_status"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); dev_stat_complete(appctx, 0, status); if (app_ctx.current_cap < DPS_CAP_CROPPINGS) dps_get_capability(app_ctx.dpsh, DPS_CAP_QUALITIES, DPS_PAPER_SIZE_DEFAULT); return DPS_RESULT_OK; }
static jresult_t td243fc_mem_alloc(td243fc_rev2_softc_t *sc, juint16_t size, juint16_t *addr) { if (size <= GET_FREE_SIZE(sc)) { *addr = sc->free_mem_start; sc->free_mem_start += size; DBG_X(DSLAVE_DCD, ("DCD: td243_mem_alloc size=%d addr=0x%.4x, free=%d" "\n", size, *addr, GET_FREE_SIZE(sc))); return 0; } return JENOMEM; }
/** * Function name: cdc_data_get * Description: Performs an asynchronous data transfer from the device to the * host. * Parameters: * @dev_ctx: (IN) CDC class driver context. * @membuf: (IN) Handle to a buffer for storing the read data. * @size: (IN) The amount of bytes to transfer. * @cb: (IN) Application completion callback. * @app_ctx: (IN) Application context. * * Return value: 0 on success, otherwise an error code. * Scope: Global **/ jresult_t cdc_data_get(uwh_cdc_dev_h dev_ctx, void *membuf, juint32_t size, cdc_general_data_cb_t cb, uwh_cdc_app_h app_ctx, void *app_priv) { DECLARE_FNAME("cdc_data_get"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); if ((GENERAL_CDC_SC(dev_ctx))->state < CDC_DEV_ENABLED) { DBG_E(DHOST_CDC_GENERAL, ("%s: device is not enabled\n", fname)); return USBD_INVALID_STATE; } return cdc_start_data_xfer(dev_ctx, membuf, size, cb, app_ctx, app_priv, GET_DATA); }
static jresult_t start_next_transfer(td243fc_rev2_softc_t *sc, jint_t ep_n) { td243fc_rev2_ep_t *ep = &sc->ep[ep_n]; KASSERT(ep_n > 1, ("No queue for ep0\n")); if (STAILQ_EMPTY(&ep->pipe->req_queue)) { DBG_X(DSLAVE_DCD, ("DCD: start_next_trasfer: queue is empty\n")); return 0; } /* Start the next request on queue */ return dcd_send_io_request((void *)sc, ep->pipe, STAILQ_FIRST(&ep->pipe->req_queue)); }
/** * Function name: cdc_encapsulated_response_get * Description: Handles a Get Encapsulated Response request from the * application. * Parameters: * @dev_ctx: (IN) CDC class driver context. * @membuf: (IN) Handle to a buffer for storing the returned response. * @size: (IN) The size of the command's data. * @cb: (IN) Application completion callback. * @app_ctx: (IN) Application context. * * Return value: 0 on success, otherwise an error code. * Scope: Global **/ jresult_t cdc_encapsulated_response_get(uwh_cdc_dev_h dev_ctx, void *membuf, juint16_t size, cdc_general_data_cb_t cb, uwh_cdc_app_h app_ctx, void *app_priv) { DECLARE_FNAME("cdc_encapsulated_response_get"); DBG_X(DHOST_CDC_GENERAL, ("cdc_encapsulated_response_get: Entered\n")); if ((GENERAL_CDC_SC(dev_ctx))->state < CDC_DEV_ATTACHED) { DBG_E(DHOST_CDC_GENERAL, ("%s: device is not enabled\n", fname)); return USBD_INVALID_STATE; } return cdc_start_encapsulated_xfer(dev_ctx, membuf, size, NULL, cb, app_ctx, app_priv, GET_ENCAP_RESPONSE); }
/** * Function name: cdc_encapsulated_command_send * Description: Handles a Send Encapsulated Command request from the * application. * Parameters: * @dev_ctx: (IN) CDC class driver context. * @cmd: (IN) Handle to a buffer containing the command to send. * @size: (IN) The size of the command's data. * @cb: (IN) Application completion callback. * @app_ctx: (IN) Application context. * * Return value: 0 on success, otherwise an error code. * Scope: Global **/ jresult_t cdc_encapsulated_command_send(uwh_cdc_dev_h dev_ctx, void *cmd, juint16_t size, cdc_general_command_cb_t cb, uwh_cdc_app_h app_ctx, void *app_priv) { DECLARE_FNAME("cdc_encapsulated_command_send"); DBG_X(DHOST_CDC_GENERAL, ("%s:: Entered\n", fname)); if ((GENERAL_CDC_SC(dev_ctx))->state < CDC_DEV_ATTACHED) { DBG_E(DHOST_CDC_GENERAL, ("%s: device is not enabled\n", fname)); return USBD_INVALID_STATE; } return cdc_start_encapsulated_xfer(dev_ctx, cmd, size, cb, NULL, app_ctx, app_priv, SEND_ENCAP_CMD); }
static jresult_t cdc_xfer_data_pipe(cdc_cmd_priv_t *priv, usbd_pipe_handle pipe, void *membuf, juint32_t size) { jresult_t rc; usbd_xfer_handle xfer = NULL; DECLARE_FNAME("cdc_xfer_data_pipe"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); rc = cdc_async_transfer(priv, pipe, membuf, size, xfer); DBG_RUN(DHOST_CDC_GENERAL, DL_EX_VERBOSE, if (rc) DBG_E(DHOST_CDC_GENERAL, ("%s: Error in xfer %p [%d]\n", fname, xfer, rc))); return rc; }
static void job_stat_complete(dps_appctx_t appctx, dps_param_t result, dps_job_status_t *status) { DECLARE_FNAME("job_stat_complete"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); if (!status) { DBG_E(DSLAVE_DPS_API, ("%s: failed to parse job status (%d)\n", fname, result)); return; } if (result) { DBG_I(DSLAVE_DPS_API, ("%s: result: %X\n", fname, result)); } DBG_I(DSLAVE_DPS_API, ("%s: DPOF: %s\n", fname, status->job_is_dpof?"yes":"no")); DBG_I(DSLAVE_DPS_API, ("%s: Progress: %u/%u\n", fname, status->pages_done, status->total_pages)); if (status->job_is_dpof) { j_memcpy(&app_ctx.dpof_restart_info, &status->dpof_params, sizeof(dpof_params_t)); app_ctx.can_restart = 1; DBG_I(DSLAVE_DPS_API, ("%s: print PID: %u\n", fname, status->dpof_params.prt_pid)); DBG_I(DSLAVE_DPS_API, ("%s: file: %s\n", fname, status->dpof_params.file_path)); DBG_I(DSLAVE_DPS_API, ("%s: page number: %u\n", fname, status->dpof_params.copy_id)); } else { #ifdef JDEBUG DBG_I(DSLAVE_DPS_API, ("%s: Images printed: %u\n", fname, status->images_printed)); #endif } }
/* Class specific requests */ static jresult_t cdc_start_encapsulated_xfer(uwh_cdc_dev_h dev_ctx, void *membuf, juint16_t size, cdc_general_command_cb_t c_cb, cdc_general_data_cb_t r_cb, uwh_cdc_app_h app_ctx, void *app_priv, cdc_req_type type) { jresult_t rc = JENOMEM; cdc_cmd_priv_t *priv = NULL; DECLARE_FNAME("cdc_start_encapsulated_xfer"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); if (!IS_CDC_SC_FULL(*(GENERAL_CDC_SC(dev_ctx)))) { DBG_E(DHOST_CDC_GENERAL, ("%s: Operation not supported\n", fname)); rc = JEINVAL; goto Error; } priv = cdc_init_request_priv(GENERAL_CDC_SC(dev_ctx), type, app_ctx, app_priv); if (!priv) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed to allocate private handle\n", fname)); goto Error; } if (type == SEND_ENCAP_CMD) priv->cdc_callback.command_cb = c_cb; else priv->cdc_callback.data_cb = r_cb; rc = encapsulated_transfer(priv, membuf, size); Error: if (rc) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed [%d]\n", fname, rc)); if (priv) cdc_uninit_request_priv(priv); } return rc; }
/* Build encapsulated cmd / response and transfer it */ static jresult_t encapsulated_transfer(cdc_cmd_priv_t *priv, void *membuf, juint16_t size) { usbd_status status = USBD_NORMAL_COMPLETION; usbd_xfer_handle xfer = NULL; jcdc_dev_softc_t *sc = priv->sc; usb_device_request_t req_t; jbool_t in_xfer = (priv->req_type == SEND_ENCAP_CMD) ? 0 : 1; DECLARE_FNAME("encapsulated_transfer"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); xfer = usbd_alloc_xfer(sc->device); if (!xfer) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed to allocate xfer\n", fname)); return JENOMEM; } /* Build request according to xfer direction */ req_t.bmRequestType = (in_xfer) ? UT_READ_CLASS_INTERFACE : UT_WRITE_CLASS_INTERFACE; req_t.bRequest = (in_xfer) ? CDC_GET_ENC_RESPONSE : CDC_SEND_ENC_COMMAND; USETW(req_t.wValue, 0); USETW(req_t.wIndex, (juint16_t)sc->c_iface->index); USETW(req_t.wLength, size); /* setup xfer */ usbd_setup_default_xfer(xfer, priv->sc->device, priv, CDC_CONTROL_XFER_TIMEOUT, &req_t, membuf, size, 0, jcdc_send_encap_cb); /* Send the request over default pipe (EP0) */ status = usbd_transfer(xfer); if (status && status != USBD_IN_PROGRESS) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed transferring control request, " "error %d\n", j_device_get_nameunit(priv->sc->dev), status)); usbd_free_xfer(xfer); return status_to_result(status); } return 0; }
static void dev_stat_complete(dps_appctx_t appctx, dps_param_t result, dps_device_status_t *status) { DECLARE_FNAME("dev_stat_complete"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); if (!status) { DBG_E(DSLAVE_DPS_API, ("%s: failed to parse device status (%d)\n", fname, result)); return; } if (result) { DBG_I(DSLAVE_DPS_API, ("%s: result: %X\n", fname, result)); } if (app_ctx.dpof_file_id && status->job_end_reason != DPS_DEV_STAT_JOB_NOT_ENDED) { sicd_store_remove_object(app_ctx.store_id, app_ctx.dpof_file_id); app_ctx.dpof_file_id = 0; j_memset(&app_ctx.dpof_restart_info, 0, sizeof(dpof_params_t)); app_ctx.can_restart = 0; } DBG_I(DSLAVE_DPS_API, ("%s: print service status: %X\n", fname, status->print_service_status)); DBG_I(DSLAVE_DPS_API, ("%s: job end reason: %X\n", fname, status->job_end_reason)); DBG_I(DSLAVE_DPS_API, ("%s: error status: %X\n", fname, status->error_status)); DBG_I(DSLAVE_DPS_API, ("%s: error reason: %X\n", fname, status->error_reason)); DBG_I(DSLAVE_DPS_API, ("%s: disconnect enabled: %X\n", fname, status->disconnect_enable)); DBG_I(DSLAVE_DPS_API, ("%s: capability changed: %X\n", fname, status->capability_changed)); DBG_I(DSLAVE_DPS_API, ("%s: new job OK: %X\n", fname, status->new_job_ok)); }
/* General CDC asynchronous transfer function */ static jresult_t cdc_async_transfer(cdc_cmd_priv_t *priv, usbd_pipe_handle pipe, void *membuf, juint32_t size, usbd_xfer_handle xfer) { jresult_t rc; usbd_status status; juint16_t flags = USBD_SHORT_XFER_OK | USBD_FORCE_SHORT_XFER; DECLARE_FNAME("cdc_async_transfer"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); /* Allocate a transfer request object and set up a xfer */ xfer = usbd_alloc_xfer(priv->sc->device); if (!xfer) { DBG_E(DHOST_CDC_GENERAL, ("%s: Failed to allocate xfer\n", fname)); rc = JENOMEM; goto Error; } usbd_setup_xfer(xfer, pipe, (void *)priv, membuf, size, flags, CDC_DATA_XFER_TIMEOUT, cdc_data_xfer_complete); /* Execute xfer */ status = usbd_transfer(xfer); if (status && status != USBD_IN_PROGRESS) { DBG_W(DHOST_CDC_GENERAL, ("%s: failed to setup transfer, %s\n", fname, usbd_errstr(status))); rc = status_to_result(status); goto Error; } return 0; Error: if (xfer) usbd_free_xfer(xfer); return rc; }
/** Test to see if the Mbr buffer is a valid MBR. @param Mbr Parent Handle. @param LastLba Last Lba address on the device. @retval TRUE Mbr is a Valid MBR. @retval FALSE Mbr is not a Valid MBR. **/ BOOLEAN PartitionValidAddLbaOfs ( IN MASTER_BOOT_RECORD *Mbr, IN EFI_LBA LastLba ) { #undef FN #define FN "PartitionValidMbr" #define DBG_PartitionValidMbr DL_80 /* DL_DISABLED DL_80 */ #if 0 UINT32 StartingLBA; UINT32 EndingLBA; UINT32 NewEndingLBA; INTN Index1; INTN Index2; #endif BOOLEAN MbrValid; EFI_LBA AddLbaOfs; #if 0 /* (MBR_SIGNATURE + 1) OVMF zeroes out 0x55AB?! */ if (Mbr->Signature != MBR_SIGNATURE + 1) { return FALSE; } #endif DBG_X(DBG_PartitionValidMbr, (PrBufxxdr((UINT8 *)&Mbr->BootStrapCode[ADDLBAOFS_SIG_OFS], ADDLBAOFS_SIG_STR_LEN))); if (CompareMem(&Mbr->BootStrapCode[ADDLBAOFS_SIG_OFS], ADDLBAOFS_SIG_STR, ADDLBAOFS_SIG_STR_LEN) != 0) { return FALSE; } AddLbaOfs = SwapBytes64(*((UINT64 *)((UINT8 *)&Mbr->BootStrapCode[ADDLBAOFS_32_OFS]))); DBG_PR(DBG_PartitionValidMbr, "AddLbaOfs=%"PRIx64"\n", AddLbaOfs); MbrValid = TRUE; return MbrValid; }
/* Command completion callback - passed to the Core for async transfers */ static void jcdc_send_encap_cb(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status rc) { /* Activate application's callback according to priv */ cdc_cmd_priv_t *cmd_priv = (cdc_cmd_priv_t *)priv; DECLARE_FNAME("jcdc_send_encap_cb"); DBG_X(DHOST_CDC_GENERAL, ("%s: Entered\n", fname)); if (cmd_priv->req_type == SEND_ENCAP_CMD) { cmd_priv->cdc_callback.command_cb(cmd_priv->app_ctx, cmd_priv->app_priv, status_to_result(rc)); } else { cmd_priv->cdc_callback.data_cb(cmd_priv->app_ctx, cmd_priv->app_priv, xfer->buffer, xfer->actlen, status_to_result(rc)); } usbd_free_xfer(xfer); cdc_uninit_request_priv(cmd_priv); }
/** Install child handles if the Handle supports AddLbaOfs format. @param[in] This Calling context. @param[in] Handle Parent Handle. @param[in] DiskIo Parent DiskIo interface. @param[in] DiskIo2 Parent DiskIo2 interface. @param[in] BlockIo Parent BlockIo interface. @param[in] BlockIo2 Parent BlockIo2 interface. @param[in] DevicePath Parent Device Path. @retval EFI_SUCCESS A child handle was added. @retval EFI_MEDIA_CHANGED Media change was detected. @retval Others MBR partition was not found. **/ EFI_STATUS PartitionInstallAddLbaOfsChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_DISK_IO2_PROTOCOL *DiskIo2, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { #undef FN #define FN "PartitionInstallAddLbaOfsChildHandles" #define DBG_PartitionInstallAddLbaOfsChildHandles DL_80 /* DL_DISABLED DL_80 */ EFI_STATUS Status; MASTER_BOOT_RECORD *Mbr; //UINT32 ExtMbrStartingLba; UINTN Index; HARDDRIVE_DEVICE_PATH HdDev; HARDDRIVE_DEVICE_PATH ParentHdDev; EFI_STATUS Found; UINT32 PartitionNumber; EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; UINT32 BlockSize; UINT32 MediaId; EFI_LBA LastBlock; EFI_LBA AddLbaOfs; EFI_LBA Lba; DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "entered\n"); Found = EFI_NOT_FOUND; BlockSize = BlockIo->Media->BlockSize; MediaId = BlockIo->Media->MediaId; LastBlock = BlockIo->Media->LastBlock; DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "BlockSize=%"PRIx64" MediaId=%"PRIx64" LastBlock=%"PRIx64"\n", BlockSize, MediaId, LastBlock); Mbr = AllocatePool (BlockSize); if (Mbr == NULL) { return Found; } for (Lba = 0; Lba < 1; Lba++) { Status = DiskIo->ReadDisk( DiskIo, MediaId, Lba * BlockSize, BlockSize, Mbr ); DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "ReadDisk MediaId=%"PRIx32" Lba*BlockSize=%"PRIx64" %r\n", MediaId, Lba * BlockSize, Status); if (!EFI_ERROR(Status)) { DBG_X(DBG_PartitionInstallAddLbaOfsChildHandles, (PrBufxxdr(Mbr, BlockSize))); if (PartitionValidAddLbaOfs (Mbr, LastBlock)) { goto ValidMbr; } } #if 0 Status = DiskIo->ReadDisk( DiskIo, MediaId, (LastBlock - Lba) * BlockSize, BlockSize, Mbr ); DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "ReadDisk MediaId=%"PRIx32" (LastBlock-Lba)*BlockSize=%"PRIx64" %r\n", MediaId, (LastBlock - Lba) * BlockSize, Status); if (!EFI_ERROR(Status)) { DBG_X(DBG_PartitionInstallAddLbaOfsChildHandles, (PrBufxxdr(Mbr, BlockSize))); if (PartitionValidAddLbaOfs (Mbr, LastBlock)) { goto ValidMbr; } } #endif } /* for */ goto Done; ValidMbr: DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "ValidMbr\n"); // // We have a valid mbr - add each partition // // // Get starting and ending LBA of the parent block device. // LastDevicePathNode = NULL; ZeroMem (&ParentHdDev, sizeof (ParentHdDev)); DevicePathNode = DevicePath; while (!IsDevicePathEnd (DevicePathNode)) { LastDevicePathNode = DevicePathNode; DevicePathNode = NextDevicePathNode (DevicePathNode); } if (LastDevicePathNode != NULL) { if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH && DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP ) { CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev)); } else { LastDevicePathNode = NULL; } } PartitionNumber = 1; ZeroMem (&HdDev, sizeof (HdDev)); HdDev.Header.Type = MEDIA_DEVICE_PATH; HdDev.Header.SubType = MEDIA_HARDDRIVE_DP; //TBD MEDIA_VENDOR_DP SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev)); HdDev.MBRType = MBR_TYPE_PCAT; //TBD HdDev.SignatureType = SIGNATURE_TYPE_GUID + 1; //TBD if (LastDevicePathNode == NULL) { // // This is a MBR, add each partition // Index = 0; /* for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { */ AddLbaOfs = SwapBytes64(*((UINT64 *)((UINT8 *)&Mbr->BootStrapCode[ADDLBAOFS_32_OFS]))); DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "AddLbaOfs=%"PRIx64"\n", AddLbaOfs); HdDev.PartitionNumber = PartitionNumber ++; HdDev.PartitionStart = AddLbaOfs; /* UNPACK_UINT32 (Mbr->Partition[Index].StartingLBA); */ HdDev.PartitionSize = LastBlock + 1 - AddLbaOfs; /* UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA); */ CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (Mbr->UniqueMbrSignature)); Status = PartitionInstallChildHandle ( This, Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, HdDev.PartitionStart, HdDev.PartitionStart + HdDev.PartitionSize - 1, MBR_SIZE, (BOOLEAN) (Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ); DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "PartitionInstallChildHandle %r\n", Status); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } /* } /* for */ } else { #if 1 //Found = EFI_NOT_FOUND; goto Done; #else // // It's an extended partition. Follow the extended partition // chain to get all the logical drives // ExtMbrStartingLba = 0; do { Status = DiskIo->ReadDisk ( DiskIo, MediaId, MultU64x32 (ExtMbrStartingLba, BlockSize), BlockSize, Mbr ); if (EFI_ERROR (Status)) { Found = Status; goto Done; } if (UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA) == 0) { break; } if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) || (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) { ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA); continue; } HdDev.PartitionNumber = PartitionNumber ++; HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart; HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA); if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) || (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) { break; } // // The signature in EBR(Extended Boot Record) should always be 0. // *((UINT32 *) &HdDev.Signature[0]) = 0; Status = PartitionInstallChildHandle ( This, Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, HdDev.PartitionStart - ParentHdDev.PartitionStart, HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1, MBR_SIZE, (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION) ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) && (Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION) ) { break; } ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[1].StartingLBA); // // Don't allow partition to be self referencing // if (ExtMbrStartingLba == 0) { break; } } while (ExtMbrStartingLba < ParentHdDev.PartitionSize); #endif } Done: FreePool (Mbr); DBG_PR(DBG_PartitionInstallAddLbaOfsChildHandles, "Found=%d\n", Found); return Found; }
static void execute_dpof_job(void) { char *dpof_file = NULL; char *dpof_jobs = NULL; sicd_object_t *obj = NULL; jint_t i; dps_job_config_t jconfig; dps_job_info_t jinfo; char *filename = NULL; DECLARE_FNAME("execute_dpof_job"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); dpof_file = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO); dpof_jobs = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO); if (!dpof_file || !dpof_jobs) { DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate job info\n", fname)); goto Error; } /* Generate JOB sections */ *dpof_jobs = '\0'; for (i=0; sample_image[i].image; i++) { if (!sicd_store_find_object(app_ctx.store_id, sample_image[i].id)) { DBG_E(DSLAVE_DPS_API, ("%s: could not find picture object " "(%X) in store\n", filename, sample_image[i].id)); goto Error; } filename = j_strdup(sample_image[i].name); if (!filename) { DBG_E(DSLAVE_DPS_API, ("%s: error allocating memory (strdup)." "skipping %s\n", fname, sample_image[i].name)); continue; } to_upper(filename); /* TODO: In a real system, the file name given here should be * the image's path relative to the DPOF file */ j_snprintf(dpof_jobs, MAX_DPOF_FILE_SIZE, DPOF_JOB_TEMPLATE, dpof_jobs, i+1, TEST_NUMBER_OF_COPIES, DCF_PREFIX, filename); jfree(filename); } dpof_jobs[MAX_DPOF_FILE_SIZE-1] = '\0'; /* Generate header */ j_snprintf(dpof_file, MAX_DPOF_FILE_SIZE, DPOF_HDR_TEMPLATE, dpof_jobs); dpof_file[MAX_DPOF_FILE_SIZE-1] = '\0'; DBG_X(DSLAVE_DPS_API, ("%s: DPOF file: \n%s\n\n", fname, dpof_file)); /* * DPOF file generation ends here. Proper API sample code * for DPOF printing begins here. */ /* Add DPOF virtual file to store */ obj = jmalloc(sizeof(sicd_object_t), M_ZERO); if (!obj) { DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate sicd_object_t " "for sample image %u\n", fname, i+1)); goto Error; } app_ctx.dpof_file_id = obj->id = sicd_get_new_obj_handle(); obj->info.storage_id = app_ctx.store_id; obj->info.format = PTP_OBJ_FORMAT_DPOF; obj->info.compressed_size = j_strlen(dpof_file)+1; obj->info.filename = ptp_string_atow("/MISC/AUTPRINT.MRK"); obj->data = (juint8_t*)dpof_file; if (sicd_store_add_object(app_ctx.store_id, obj)) { DBG_E(DSLAVE_DPS_API, ("generate_dpof: failed on " "sicd_store_add_object (%u)\n")); goto Error; } /* Create JobInfo for DPOF file */ j_memset(&jconfig, 0, sizeof(jconfig)); jconfig.file_type = DPS_FILE_TYPE_DPOF; j_memset(&jinfo, 0, sizeof(jinfo)); jinfo.file_id = obj->id; j_strlcpy(jinfo.file_name, "/MISC/AUTPRINT.MRK", DPS_FILENAME_SIZE + 1); /* If we are testing DPOF restart, add relevant parameters */ if (TEST_DPOF_RESTART && app_ctx.can_restart) { j_memcpy(&jinfo.dpof_restart, &app_ctx.dpof_restart_info, sizeof(dpof_params_t)); } /* Send Job */ dps_start_job(app_ctx.dpsh, &jconfig, &jinfo, 1); goto Exit; Error: if (obj) sicd_free_object(NULL, obj); else if (dpof_file) jfree(dpof_file); Exit: if (dpof_jobs) jfree(dpof_jobs); }
void get_cap_complete(dps_appctx_t appctx, dps_param_t result, dps_cap_array_t *cap_list) { static char dbg_buf[1000]; jint_t i, j; dps_param_t conf_setting = 0; static struct { char *cap_str; dps_param_t *conf_param; dps_param_t test_value; dps_param_t default_value; } cap_map[] = { { "print qualities", &app_ctx.jconfig.quality, TEST_DPS_QUALITY, DPS_QUALITY_DEFAULT }, { "paper sizes", &app_ctx.jconfig.paper_size, TEST_DPS_PAPER_SIZE, DPS_PAPER_SIZE_DEFAULT }, { "paper types", &app_ctx.jconfig.paper_type, TEST_DPS_PAPER_TYPE, DPS_PAPER_TYPE_DEFAULT }, { "file types", &app_ctx.jconfig.file_type, TEST_DPS_FILE_TYPE, DPS_FILE_TYPE_DEFAULT }, { "date prints", &app_ctx.jconfig.date_print, TEST_DPS_DATE_PRINT, DPS_DATE_PRINT_DEFAULT }, { "filename prints", &app_ctx.jconfig.filename_print, TEST_DPS_FILENAME_PRINT, DPS_FILENAME_PRINT_DEFAULT }, { "image optimizations", &app_ctx.jconfig.image_optimize, TEST_DPS_IMAGE_OPTIMIZE, DPS_IMAGE_OPTIMIZE_DEFAULT }, { "layouts", &app_ctx.jconfig.layout, TEST_DPS_LAYOUT, DPS_LAYOUT_DEFAULT }, { "fixed paper sizes", &app_ctx.jconfig.fixed_size, TEST_DPS_FIXED_SIZE, DPS_FIXED_SIZE_DEFAULT }, { "croppings", &app_ctx.jconfig.cropping, TEST_DPS_CROPPING, DPS_CROPPING_DEFAULT }, }; DECLARE_FNAME("get_cap_complete"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); if (result!=DPS_RESULT_OK || !cap_list || !cap_list->count || app_ctx.current_cap > DPS_CAP_CROPPINGS) { goto NextCapability; } /* Print out supported parameters */ *dbg_buf = 0; i = app_ctx.current_cap; for (j=0; j<cap_list->count; j++) { j_snprintf(dbg_buf, sizeof(dbg_buf)-1, "%s 0x%X", dbg_buf, cap_list->capability[j]); if (cap_map[i].test_value == cap_list->capability[j]) conf_setting = cap_map[i].test_value; } DBG_I(DSLAVE_DPS_API, ("%s: Supported %s: %s\n", fname, cap_map[app_ctx.current_cap].cap_str, dbg_buf)); /* Set print config parameter */ if (conf_setting) { *(cap_map[i].conf_param) = conf_setting; DBG_I(DSLAVE_DPS_API, ("%s:\t0x%X selected\n", fname, conf_setting)); } else { *(cap_map[i].conf_param) = cap_map[i].default_value; DBG_W(DSLAVE_DPS_API, ("%s:\t0x%X is not supported by the printer." " using default (0x%X)\n", fname, cap_map[i].test_value, cap_map[i].default_value)); } NextCapability: if (app_ctx.current_cap >= DPS_CAP_CROPPINGS) { /* Done with capabilities - send a print job */ execute_job(); } else { /* Get more capabilities from printer */ app_ctx.current_cap++; dps_get_capability(app_ctx.dpsh, app_ctx.current_cap, app_ctx.jconfig.paper_size); } }