int main(int argc, char *argv[]) { uint32_t ret; STACK_TPM_BUFFER(resp); int index = 0; STACK_TPM_BUFFER( subcap );; TPM_setlog(0); /* turn off verbose output */ ParseArgs(argc, argv); while ((int)matrx[index].cap != -1) { if (cap == matrx[index].cap) { break; } index++; } if (-1 == (int)matrx[index].cap) { printf("Unknown or unsupported capability!\n"); exit(-1); } subcap.used = 0; if (matrx[index].subcap_size > 0) { if ((int)scap == -1) { printf("Need subcap parameter for this capability!\n"); exit(-1); } if (0 == prepare_subcap(cap, &subcap, scap)) { if (2 == matrx[index].subcap_size) { STORE16(subcap.buffer,0,scap); subcap.used = 2; } else if (matrx[index].subcap_size >= 4) { STORE32(subcap.buffer,0,scap); subcap.used = 4; } } } #if 0 /* This was for VTPM extensions and needs retest */ if (cap == TPM_CAP_MFR) { int idx2 = 0; while ((int)mfr_matrix[idx2].cap != -1) { if (mfr_matrix[idx2].cap == scap) { break; } idx2++; } if (mfr_matrix[idx2].subcap_size > 0) { uint32_t used = subcap.used + mfr_matrix[idx2].subcap_size; while (subcap.used < used) { if (argc <= nxtarg) { printf("Need one more parameter for this " "capability!\n"); exit(-1); } if (!strncmp("0x",argv[nxtarg],2)) { sscanf(argv[nxtarg],"%x",&sscap); } else { sscanf(argv[nxtarg],"%d",&sscap); } nxtarg++; if (2 == matrx[index].subcap_size) { STORE16(subcap.buffer, subcap.used,sscap); subcap.used += 2; } else if (matrx[index].subcap_size >= 4) { STORE32(subcap.buffer, subcap.used,sscap); subcap.used += 4; } } } } #endif if (0 == sikeyhandle) { ret = TPM_GetCapability(cap, &subcap, &resp); if (0 != ret) { printf("TPM_GetCapability returned %s.\n", TPM_GetErrMsg(ret)); exit(ret); } } else { unsigned char antiReplay[TPM_HASH_SIZE]; unsigned char signature[2048]; uint32_t signaturelen = sizeof(signature); pubkeydata pubkey; RSA * rsa; unsigned char sighash[TPM_HASH_SIZE]; unsigned char * buffer = NULL; unsigned char * sigkeyhashptr = NULL; unsigned char sigkeypasshash[TPM_HASH_SIZE]; if (NULL != sikeypass) { TSS_sha1(sikeypass,strlen(sikeypass),sigkeypasshash); sigkeyhashptr = sigkeypasshash; } TSS_gennonce(antiReplay); ret = TPM_GetPubKey(sikeyhandle, sigkeyhashptr, &pubkey); if (0 != ret) { printf("Error while trying to access the signing key's public key.\n"); exit(-1); } rsa = TSS_convpubkey(&pubkey); ret = TPM_GetCapabilitySigned(sikeyhandle, sigkeyhashptr, antiReplay, cap, &subcap, &resp, signature, &signaturelen); if (0 != ret) { printf("TPM_GetCapabilitySigned returned %s.\n", TPM_GetErrMsg(ret)); exit(ret); } buffer = malloc(resp.used+TPM_NONCE_SIZE); if (NULL == buffer) { printf("Could not allocate buffer.\n"); exit(-1); } memcpy(&buffer[0], resp.buffer, resp.used); memcpy(&buffer[resp.used], antiReplay, TPM_NONCE_SIZE); TSS_sha1(buffer, resp.used+TPM_NONCE_SIZE, sighash); free(buffer); ret = RSA_verify(NID_sha1, sighash,TPM_HASH_SIZE, signature,signaturelen, rsa); if (1 != ret) { printf("Error: Signature verification failed.\n"); exit(-1); } } if (0 == resp.used) { printf("Empty response.\n"); } else { if (-1 == (int)scap) { printf("Result for capability 0x%x is : ",cap); } else { printf("Result for capability 0x%x, subcapability 0x%x is : ",cap,scap); } if (TYPE_BOOL == matrx[index].result_size) { if (resp.buffer[0] == 0) { printf("FALSE\n"); } else { printf("TRUE\n"); } } else if (TYPE_UINT32 == matrx[index].result_size) { uint32_t rsp; rsp = LOAD32(resp.buffer,0); printf("0x%08X = %d\n",rsp,rsp); } else if (TYPE_UINT32_ARRAY == matrx[index].result_size) { int i = 0; printf("\n"); while (i+3 < (int)resp.used) { uint32_t rsp = LOAD32(resp.buffer,i); i+=4; if (TPM_CAP_NV_LIST == cap) { /* don't zero extend, grep needs the exact value for test suite */ printf("%d. Index : %d = 0x%x.\n", i/4, rsp, rsp); } else if (TPM_CAP_KEY_HANDLE == cap) { printf("%d. keyhandle : %d.\n", i/4, rsp); } else { printf("%d. item : %d.\n", i/4, rsp); } } } else if (TYPE_STRUCTURE == matrx[index].result_size) { switch(cap) { case TPM_CAP_FLAG: { if (scap == TPM_CAP_FLAG_PERMANENT) { TPM_PERMANENT_FLAGS pf; STACK_TPM_BUFFER(tb) TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadPermanentFlags(&tb, 0, &pf, resp.used); if ( ( ret & ERR_MASK ) != 0 || ret > resp.used) { printf("ret=%x, responselen=%d\n",ret,resp.used); printf("Error parsing response!\n"); exit(-1); } printf("\n"); showPermanentFlags(&pf, resp.used); } else if (scap == TPM_CAP_FLAG_VOLATILE) { TPM_STCLEAR_FLAGS sf; STACK_TPM_BUFFER(tb); TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadSTClearFlags(&tb, 0, &sf); if ( ( ret & ERR_MASK ) != 0 || ret > resp.used) { printf("ret=%x, responselen=%d\n",ret,resp.used); printf("Error parsing response!\n"); exit(-1); } printf("\n"); showVolatileFlags(&sf); } } break; case TPM_CAP_KEY_HANDLE: { uint16_t num = LOAD16(resp.buffer, 0); uint32_t i = 0; uint32_t handle; printf("\n"); while (i < num) { handle = LOAD32(resp.buffer,2+i*4); printf("%d. handle: 0x%08X\n", i, handle); i++; } } break; case TPM_CAP_NV_INDEX: { //char scratch_info[256]; unsigned char scratch_info[256]; uint32_t scratch_info_len; TPM_NV_DATA_PUBLIC ndp; uint32_t i, c; STACK_TPM_BUFFER(tb) TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadNVDataPublic(&tb, 0, &ndp); if ( ( ret & ERR_MASK) != 0) { printf("Could not deserialize the TPM_NV_DATA_PUBLIC structure.\n"); exit(-1); } printf("permission.attributes : %08X\n",(unsigned int)ndp.permission.attributes); printf("ReadSTClear : %02X\n",ndp.bReadSTClear); printf("WriteSTClear : %02X\n",ndp.bWriteSTClear); printf("WriteDefine : %02X\n",ndp.bWriteDefine); printf("dataSize : %08X = %d",(unsigned int)ndp.dataSize, (unsigned int)ndp.dataSize); c = 0; for (i = 0; i < ndp.pcrInfoRead.pcrSelection.sizeOfSelect*8; i++) { if (ndp.pcrInfoRead.pcrSelection.pcrSelect[(i / 8)] & (1 << (i & 0x7))) { if (!c) printf("\nRead PCRs selected: "); else printf(", "); printf("%d", i); c++; } } if (c) { char pcrmap[4], *pf; memcpy(pcrmap, ndp.pcrInfoRead.pcrSelection.pcrSelect, ndp.pcrInfoRead.pcrSelection.sizeOfSelect); // printf("\npcrmap: %02x%02x%02x%02x\n", pcrmap[0], pcrmap[1], // pcrmap[2], pcrmap[3]); ret = TSS_GenPCRInfo(*(uint32_t *)pcrmap, scratch_info, &scratch_info_len); printf("\nRead PCR Composite: "); for (i = 0; i < 20; i++) printf("%02x", ndp.pcrInfoRead.digestAtRelease[i] & 0xff); printf("\n"); #if 1 pf = &scratch_info[5]; printf("\nCurrent PCR composite: "); for (i = 0; i < 20; i++) //printf("%02x", scratch_info.digestAtRelease[i] & 0xff); printf("%02x", pf[i] & 0xff); printf("\n"); #endif if (!ret) { printf("Matches current TPM state: "); if (!memcmp(&scratch_info[5], &ndp.pcrInfoRead.digestAtRelease, 20)) { printf("Yes\n"); } else { printf("No\n"); } } } c = 0; for (i = 0; i < ndp.pcrInfoWrite.pcrSelection.sizeOfSelect*8; i++) { if (ndp.pcrInfoWrite.pcrSelection.pcrSelect[(i / 8)] & (1 << (i & 0x7))) { if (!c) printf("\nWrite PCRs selected: "); else printf(", "); printf("%d", i); c++; } } if (c) { printf("\nWrite PCR Composite: "); for (i = 0; i < 20; i++) printf("%02x", ndp.pcrInfoWrite.digestAtRelease[i] & 0xff); printf("\n"); } } break; case TPM_CAP_HANDLE: { uint16_t num = LOAD16(resp.buffer, 0); uint16_t x = 0; while (x < num) { uint32_t handle = LOAD32(resp.buffer, sizeof(num)+4*x); printf("%02d. 0x%08X\n",x,handle); x++; } } break; case TPM_CAP_VERSION_VAL: { int i = 0; TPM_CAP_VERSION_INFO cvi; STACK_TPM_BUFFER(tb) TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadCapVersionInfo(&tb, 0, &cvi); if ( ( ret & ERR_MASK) != 0) { printf("Could not read the version info structure.\n"); exit(-1); } printf("\n"); printf("major : 0x%02X\n",cvi.version.major); printf("minor : 0x%02X\n",cvi.version.minor); printf("revMajor : 0x%02X\n",cvi.version.revMajor); printf("revMinor : 0x%02X\n",cvi.version.revMinor); printf("specLevel : 0x%04X\n",cvi.specLevel); printf("errataRev : 0x%02X\n",cvi.errataRev); printf("VendorID : "); while (i < 4) { printf("%02X ",cvi.tpmVendorID[i]); i++; } printf("\n"); /* Print vendor ID in text if printable */ for (i=0 ; i<4 ; i++) { if (isprint(cvi.tpmVendorID[i])) { if (i == 0) { printf("VendorID : "); } printf("%c", cvi.tpmVendorID[i]); } else { break; } } printf("\n"); printf("[not displaying vendor specific information]\n"); } break; #if 0 /* kgold: I don't think these are valid cap values */ case TPM_CAP_FLAG_PERMANENT: { TPM_PERMANENT_FLAGS pf; STACK_TPM_BUFFER(tb) TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); if (resp.used == 21) { ret = TPM_ReadPermanentFlagsPre103(&tb, 0, &pf); } else { ret = TPM_ReadPermanentFlags(&tb, 0, &pf); } if ( ( ret & ERR_MASK ) != 0 || ret > resp.used) { printf("ret=%x, responselen=%d\n",ret,resp.used); printf("Error parsing response!\n"); exit(-1); } printf("\n"); showPermanentFlags(&pf, resp.used); } break; case TPM_CAP_FLAG_VOLATILE: { TPM_STCLEAR_FLAGS sf; STACK_TPM_BUFFER(tb); TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadSTClearFlags(&tb, 0, &sf); if ( ( ret & ERR_MASK ) != 0 || ret > resp.used) { printf("ret=%x, responselen=%d\n",ret,resp.used); printf("Error parsing response!\n"); exit(-1); } printf("\n"); showVolatileFlags(&sf); } break; #endif case TPM_CAP_DA_LOGIC: { uint32_t ctr; TPM_BOOL lim = FALSE; TPM_DA_INFO dainfo; TPM_DA_INFO_LIMITED dainfo_lim; STACK_TPM_BUFFER(tb); TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); ret = TPM_ReadDAInfo(&tb, 0, &dainfo); if ( ( ret & ERR_MASK) != 0 || ret > resp.used) { ret = TPM_ReadDAInfoLimited(&tb, 0, &dainfo_lim); if ( (ret & ERR_MASK ) != 0 || ret > resp.used) { printf("ret=%x, responselen=%d\n",ret,resp.used); printf("Error parsing response!\n"); exit(-1); } else { lim = TRUE; } } printf("\n"); if (lim) { printf("State : %d\n",dainfo_lim.state); printf("Actions : 0x%08x\n",dainfo_lim.actionAtThreshold.actions); ctr = 0; while (ctr < dainfo_lim.vendorData.size) { printf("%02x ",(unsigned char)dainfo_lim.vendorData.buffer[ctr]); ctr++; } } else { printf("State : %d\n",dainfo.state); printf("currentCount : %d\n",dainfo.currentCount); printf("thresholdCount : %d\n",dainfo.thresholdCount); printf("Actions : 0x%08x\n",dainfo.actionAtThreshold.actions); printf("actionDependValue : %d\n",dainfo.actionDependValue); #if 0 ctr = 0; while (ctr < dainfo_lim.vendorData.size) { printf("%02x ",(unsigned char)dainfo_lim.vendorData.buffer[ctr]); ctr++; } #endif } } break; } } else if (TYPE_VARIOUS == matrx[index].result_size) { switch(cap) { case TPM_CAP_MFR: switch (scap) { case TPM_CAP_PROCESS_ID: { uint32_t rsp; rsp = LOAD32(resp.buffer,0); printf("%d\n",rsp); } break; } break; /* TPM_CAP_MFR */ default: /* Show booleans */ if (scap == TPM_CAP_PROP_OWNER || scap == TPM_CAP_PROP_DAA_INTERRUPT ) { if (0 == resp.buffer[0]) { printf("FALSE\n"); } else { printf("TRUE\n"); } } else /* check for array of 4 UINTs */ if (scap == TPM_CAP_PROP_TIS_TIMEOUT /* || scap == TPM_CAP_PROP_TIMEOUTS */) { int i = 0; while (i < 4) { uint32_t val = LOAD32(resp.buffer,i * 4); printf("%d ", val); i++; } printf("\n"); } else /* check for TPM_STARTUP_EFFECTS */ if (scap == TPM_CAP_PROP_STARTUP_EFFECT) { TPM_STARTUP_EFFECTS se = 0; ret = TPM_ReadStartupEffects(resp.buffer, &se); if ( ( ret & ERR_MASK ) != 0 ) { printf("Could not read startup effects structure.\n"); exit(-1); } printf("0x%08X=%d\n", (unsigned int)se, (unsigned int)se); printf("\n"); printf("Startup effects:\n"); printf("Effect on audit digest: %s\n", (se & (1 << 7)) ? "none" : "active"); printf("Audit Digest on TPM_Startup(ST_CLEAR): %s\n", ( se & (1 << 6)) ? "set to NULL" : "not set to NULL" ); printf("Audit Digest on TPM_Startup(any) : %s\n", ( se & (1 << 5)) ? "set to NULL" : "not set to NULL" ); printf("TPM_RT_KEY resource initialized on TPM_Startup(ST_ANY) : %s\n", (se & ( 1 << 4)) ? "yes" : "no"); printf("TPM_RT_AUTH resource initialized on TPM_Startup(ST_STATE) : %s\n", (se & ( 1 << 3)) ? "yes" : "no"); printf("TPM_RT_HASH resource initialized on TPM_Startup(ST_STATE) : %s\n", (se & ( 1 << 2)) ? "yes" : "no"); printf("TPM_RT_TRANS resource initialized on TPM_Startup(ST_STATE) : %s\n", (se & ( 1 << 1)) ? "yes" : "no"); printf("TPM_RT_CONTEXT session initialized on TPM_Startup(ST_STATE): %s\n", (se & ( 1 << 0)) ? "yes" : "no"); } else /* check for array of 3 UINTs */ if (scap == TPM_CAP_PROP_DURATION) { int i = 0; while (i < 4*3) { uint32_t val = LOAD32(resp.buffer,i); printf("%d ", val); i+= 4; } printf("\n"); } else /* check for TPM_COUNT_ID */ if (scap == TPM_CAP_PROP_ACTIVE_COUNTER) { uint32_t val = LOAD32(resp.buffer,0); printf("0x%08X=%d",val,val); if (0xffffffff == val) { printf(" (no counter is active)"); } printf("\n"); } else { /* just a single UINT32 */ printf("%ld=0x%08lX.\n", (long)LOAD32(resp.buffer, 0), (long)LOAD32(resp.buffer, 0)); } } } } printf("\n"); exit(0); }
/* Process 2OPI Integer instructions */ bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c) { #ifdef DEBUG char Name[20] = "ILLEGAL_2OPI"; #endif /* 0x0E ... 0x2B */ /* 0xB0 ... 0xDF */ switch(c->raw2) { case 0x0E: /* ADDI */ { #ifdef DEBUG strncpy(Name, "ADDI", 19); #elif TRACE record_trace("ADDI"); #endif ADDI(vm, c); break; } case 0x0F: /* ADDUI */ { #ifdef DEBUG strncpy(Name, "ADDUI", 19); #elif TRACE record_trace("ADDUI"); #endif ADDUI(vm, c); break; } case 0x10: /* SUBI */ { #ifdef DEBUG strncpy(Name, "SUBI", 19); #elif TRACE record_trace("SUBI"); #endif SUBI(vm, c); break; } case 0x11: /* SUBUI */ { #ifdef DEBUG strncpy(Name, "SUBUI", 19); #elif TRACE record_trace("SUBUI"); #endif SUBUI(vm, c); break; } case 0x12: /* CMPI */ { #ifdef DEBUG strncpy(Name, "CMPI", 19); #elif TRACE record_trace("CMPI"); #endif CMPI(vm, c); break; } case 0x13: /* LOAD */ { #ifdef DEBUG strncpy(Name, "LOAD", 19); #elif TRACE record_trace("LOAD"); #endif LOAD(vm, c); break; } case 0x14: /* LOAD8 */ { #ifdef DEBUG strncpy(Name, "LOAD8", 19); #elif TRACE record_trace("LOAD8"); #endif LOAD8(vm, c); break; } case 0x15: /* LOADU8 */ { #ifdef DEBUG strncpy(Name, "LOADU8", 19); #elif TRACE record_trace("LOADU8"); #endif LOADU8(vm, c); break; } case 0x16: /* LOAD16 */ { #ifdef DEBUG strncpy(Name, "LOAD16", 19); #elif TRACE record_trace("LOAD16"); #endif LOAD16(vm, c); break; } case 0x17: /* LOADU16 */ { #ifdef DEBUG strncpy(Name, "LOADU16", 19); #elif TRACE record_trace("LOADU16"); #endif LOADU16(vm, c); break; } case 0x18: /* LOAD32 */ { #ifdef DEBUG strncpy(Name, "LOAD32", 19); #elif TRACE record_trace("LOAD32"); #endif LOAD32(vm, c); break; } case 0x19: /* LOADU32 */ { #ifdef DEBUG strncpy(Name, "LOADU32", 19); #elif TRACE record_trace("LOADU32"); #endif LOADU32(vm, c); break; } case 0x1F: /* CMPUI */ { #ifdef DEBUG strncpy(Name, "CMPUI", 19); #elif TRACE record_trace("CMPUI"); #endif CMPUI(vm, c); break; } case 0x20: /* STORE */ { #ifdef DEBUG strncpy(Name, "STORE", 19); #elif TRACE record_trace("STORE"); #endif STORE(vm, c); break; } case 0x21: /* STORE8 */ { #ifdef DEBUG strncpy(Name, "STORE8", 19); #elif TRACE record_trace("STORE8"); #endif STORE8(vm, c); break; } case 0x22: /* STORE16 */ { #ifdef DEBUG strncpy(Name, "STORE16", 19); #elif TRACE record_trace("STORE16"); #endif STORE16(vm, c); break; } case 0x23: /* STORE32 */ { #ifdef DEBUG strncpy(Name, "STORE32", 19); #elif TRACE record_trace("STORE32"); #endif STORE32(vm, c); break; } case 0xB0: /* ANDI */ { #ifdef DEBUG strncpy(Name, "ANDI", 19); #elif TRACE record_trace("ANDI"); #endif ANDI(vm, c); break; } case 0xB1: /* ORI */ { #ifdef DEBUG strncpy(Name, "ORI", 19); #elif TRACE record_trace("ORI"); #endif ORI(vm, c); break; } case 0xB2: /* XORI */ { #ifdef DEBUG strncpy(Name, "XORI", 19); #elif TRACE record_trace("XORI"); #endif XORI(vm, c); break; } case 0xB3: /* NANDI */ { #ifdef DEBUG strncpy(Name, "NANDI", 19); #elif TRACE record_trace("NANDI"); #endif NANDI(vm, c); break; } case 0xB4: /* NORI */ { #ifdef DEBUG strncpy(Name, "NORI", 19); #elif TRACE record_trace("NORI"); #endif NORI(vm, c); break; } case 0xB5: /* XNORI */ { #ifdef DEBUG strncpy(Name, "XNORI", 19); #elif TRACE record_trace("XNORI"); #endif XNORI(vm, c); break; } case 0xC0: /* CMPJUMPI.G */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.G", 19); #elif TRACE record_trace("CMPJUMPI.G"); #endif CMPJUMPI_G(vm, c); break; } case 0xC1: /* CMPJUMPI.GE */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.GE", 19); #elif TRACE record_trace("CMPJUMPI.GE"); #endif CMPJUMPI_GE(vm, c); break; } case 0xC2: /* CMPJUMPI.E */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.E", 19); #elif TRACE record_trace("CMPJUMPI.E"); #endif CMPJUMPI_E(vm, c); break; } case 0xC3: /* CMPJUMPI.NE */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.NE", 19); #elif TRACE record_trace("CMPJUMPI.NE"); #endif CMPJUMPI_NE(vm, c); break; } case 0xC4: /* CMPJUMPI.LE */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.LE", 19); #elif TRACE record_trace("CMPJUMPI.LE"); #endif CMPJUMPI_LE(vm, c); break; } case 0xC5: /* CMPJUMPI.L */ { #ifdef DEBUG strncpy(Name, "CMPJUMPI.L", 19); #elif TRACE record_trace("CMPJUMPI.L"); #endif CMPJUMPI_L(vm, c); break; } case 0xD0: /* CMPJUMPUI.G */ { #ifdef DEBUG strncpy(Name, "CMPJUMPUI.G", 19); #elif TRACE record_trace("CMPJUMPUI.G"); #endif CMPJUMPUI_G(vm, c); break; } case 0xD1: /* CMPJUMPUI.GE */ { #ifdef DEBUG strncpy(Name, "CMPJUMPUI.GE", 19); #elif TRACE record_trace("CMPJUMPUI.GE"); #endif CMPJUMPUI_GE(vm, c); break; } case 0xD4: /* CMPJUMPUI.LE */ { #ifdef DEBUG strncpy(Name, "CMPJUMPUI.LE", 19); #elif TRACE record_trace("CMPJUMPUI.LE"); #endif CMPJUMPUI_LE(vm, c); break; } case 0xD5: /* CMPJUMPUI.L */ { #ifdef DEBUG strncpy(Name, "CMPJUMPUI.L", 19); #elif TRACE record_trace("CMPJUMPUI.L"); #endif CMPJUMPUI_L(vm, c); break; } default: { illegal_instruction(vm, c); break; } } #ifdef DEBUG fprintf(stdout, "# %s reg%u reg%u %i\n", Name, c->reg0, c->reg1, c->raw_Immediate); #endif return false; }
static SANE_Status set_window (Abaton_Scanner * s) { uint8_t cmd[10 + 40]; uint8_t *window = cmd + 10 + 8; int invert; memset (cmd, 0, sizeof (cmd)); cmd[0] = SET_WINDOW; cmd[8] = 40; /* Just like the Apple scanners, we put the resolution here */ STORE16 (window + 2, s->val[OPT_X_RESOLUTION].w); STORE16 (window + 4, s->val[OPT_Y_RESOLUTION].w); /* Unlike Apple scanners, these are pixel values */ STORE16 (window + 6, s->ULx); STORE16 (window + 8, s->ULy); STORE16 (window + 10, s->Width); STORE16 (window + 12, s->Height); STORE8 (window + 14, s->val[OPT_BRIGHTNESS].w); STORE8 (window + 15, s->val[OPT_THRESHOLD].w); STORE8 (window + 16, s->val[OPT_CONTRAST].w); invert = s->val[OPT_NEGATIVE].w; if (!strcmp (s->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_LINEART)) { STORE8 (window + 17, 0); } else if (!strcmp (s->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_HALFTONE)) { STORE8 (window + 17, 1); } else if (!strcmp (s->val[OPT_MODE].s, "Gray256") || !strcmp (s->val[OPT_MODE].s, "Gray16")) { STORE8 (window + 17, 2); invert = !s->val[OPT_NEGATIVE].w; } else { DBG (ERROR_MESSAGE, "Can't match mode %s\n", s->val[OPT_MODE].s); return SANE_STATUS_INVAL; } STORE8 (window + 18, s->bpp); if (!strcmp (s->val[OPT_HALFTONE_PATTERN].s, "spiral")) { STORE8 (window + 20, 0); } else if (!strcmp (s->val[OPT_HALFTONE_PATTERN].s, "bayer")) { STORE8 (window + 20, 1); } else { DBG (ERROR_MESSAGE, "Can't match haftone pattern %s\n", s->val[OPT_HALFTONE_PATTERN].s); return SANE_STATUS_INVAL; } /* We have to invert these ones for some reason, so why not let the scanner do it for us... */ STORE8 (window + 21, invert ? 0x80 : 0); STORE16 (window + 22, (s->val[OPT_MIRROR].w != 0)); return sanei_scsi_cmd (s->fd, cmd, sizeof (cmd), 0, 0); }