void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code, u8 a_sense_code, u8 incorrect_length, u8 bit_pointer, u16 field_pointer, u32 residue) { sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */ sense_buf[1] = 0; /* Segment number, always zero */ if (incorrect_length) { sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */ sense_buf[3] = BYTE3(residue); sense_buf[4] = BYTE2(residue); sense_buf[5] = BYTE1(residue); sense_buf[6] = BYTE0(residue); } else sense_buf[2] = sense_key; /* Sense key */ if (sense_key == SENKEY_ILLEGAL) sense_buf[7] = 10; /* Additional sense length */ else sense_buf[7] = 6; /* Additional sense length */ sense_buf[12] = sense_code; /* Additional sense code */ sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ if (sense_key == SENKEY_ILLEGAL) { sense_buf[15] = 0; if (sense_code == SENCODE_INVALID_PARAM_FIELD) sense_buf[15] = 0x80;/* Std sense key specific field */ /* Illegal parameter is in the parameter block */ if (sense_code == SENCODE_INVALID_CDB_FIELD) sense_buf[15] = 0xc0;/* Std sense key specific field */ /* Illegal parameter is in the CDB block */ sense_buf[15] |= bit_pointer; sense_buf[16] = field_pointer >> 8; /* MSB */ sense_buf[17] = field_pointer; /* LSB */ }
void Commander::Send_Status(void) { u8 _cnt=0; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0x01; data_to_send[_cnt++]=0; vs16 _temp; _temp = (int)(imu.angle.x*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); _temp = (int)(imu.angle.y*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); _temp = (int)(imu.angle.z*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); _temp = (int)(1000); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); vs32 _temp2 = 100;//UltraAlt * 100; data_to_send[_cnt++]=BYTE3(_temp2); data_to_send[_cnt++]=BYTE2(_temp2); data_to_send[_cnt++]=BYTE1(_temp2); data_to_send[_cnt++]=BYTE0(_temp2); data_to_send[3] = _cnt-4; u8 sum = 0; for(u8 i=0;i<_cnt;i++) sum += data_to_send[i]; data_to_send[_cnt++]=sum; Send_Data(data_to_send, _cnt); }
void Send_Status(void) { u8 _cnt=0; u8 i; vs16 _temp; vs32 _temp2 = 0;//UltraAlt * 100; u8 sum = 0; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0x01; data_to_send[_cnt++]=0; _temp = (int)(IMU_QCF.roll*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); _temp = (int)(IMU_QCF.pitch*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); _temp = (int)(IMU_QCF.yaw*100); data_to_send[_cnt++]=BYTE1(_temp); data_to_send[_cnt++]=BYTE0(_temp); data_to_send[_cnt++]=BYTE3(_temp2); data_to_send[_cnt++]=BYTE2(_temp2); data_to_send[_cnt++]=BYTE1(_temp2); data_to_send[_cnt++]=BYTE0(_temp2); data_to_send[3] = _cnt-4; for(i=0;i<_cnt;i++) sum += data_to_send[i]; data_to_send[_cnt++]=sum; Send_Data(data_to_send, _cnt); }
/* putc() with code conversion */ int putc2(int c, FILE *fp) { static int num[NOFILE]; /* 0 : not in Kanji 1..4 : in JIS Kanji and num[] bytes are in store[][] -1 : in JIS Kanji and store[][] is empty */ static unsigned char store[NOFILE][4]; const int fd = fileno(fp); int ret = c, output_enc; #ifdef WIN32 if ((fp == stdout || fp == stderr) && (_isatty(fd) || !prior_file_enc)) { if (sjisterminal) { if (is_internalUPTEX()) output_enc = ENC_UTF8; else output_enc = ENC_SJIS; } else #else if ((fp == stdout || fp == stderr) && !prior_file_enc) { #endif output_enc = get_terminal_enc(); } else output_enc = get_file_enc(); if (num[fd] > 0) { /* multi-byte char */ if (is_internalUPTEX() && iskanji1(c)) { /* error */ ret = flush(store[fd], num[fd], fp); num[fd] = 0; } store[fd][num[fd]] = c; num[fd]++; if (multistrlen(store[fd], num[fd], 0) == num[fd]) { long i = fromBUFF(store[fd], num[fd], 0); ret = put_multibyte(toENC(i, output_enc), fp); num[fd] = -1; } else if ((is_internalUPTEX() && num[fd] == 4) || (!is_internalUPTEX() && num[fd] == 2)) { /* error */ ret = flush(store[fd], num[fd], fp); num[fd] = -1; } } else if (iskanji1(c)) { /* first multi-byte char */ if (num[fd] == 0 && output_enc == ENC_JIS) { ret = put_multibyte(KANJI_IN, fp); } store[fd][0] = c; num[fd] = 1; } else { /* ASCII */ if (num[fd] < 0 && output_enc == ENC_JIS) { put_multibyte(KANJI_OUT, fp); } ret = putc(c, fp); num[fd] = 0; } return ret; } /* fputs() with code conversion */ int fputs2(const char *s, FILE *fp) { while (*s != '\0') { int ret = putc2((unsigned char)*s, fp); if (ret == EOF) return EOF; s++; } return 1; } static struct unget_st { int size; int buff[4]; } ungetbuff[NOFILE]; static int getc4(FILE *fp) { struct unget_st *p = &ungetbuff[fileno(fp)]; if (p->size == 0) #ifdef WIN32 { const int fd = fileno(fp); HANDLE hStdin; DWORD ret; wchar_t wc[2]; long c; static wchar_t wcbuf = L'\0'; if (!(fd == fileno(stdin) && _isatty(fd) && is_internalUPTEX())) return getc(fp); hStdin = GetStdHandle(STD_INPUT_HANDLE); if (wcbuf) { wc[0] = wcbuf; wcbuf = L'\0'; } else if (ReadConsoleW(hStdin, wc, 1, &ret, NULL) == 0) return EOF; if (0xd800<=wc[0] && wc[0]<0xdc00) { if (ReadConsoleW(hStdin, wc+1, 1, &ret, NULL) == 0) return EOF; if (0xdc00<=wc[1] && wc[1]<0xe000) { c = UTF16StoUTF32(wc[0], wc[1]); } else { wcbuf = wc[1]; c = U_REPLACEMENT_CHARACTER; /* illegal upper surrogate pair */ } } else if (0xdc00<=wc[0] && wc[0]<0xe000) { c = U_REPLACEMENT_CHARACTER; /* illegal lower surrogate pair */ } else { c = wc[0]; } c = UCStoUTF8(c); /* always */ p->buff[p->size++]=BYTE4(c); if (BYTE3(c) != 0) p->buff[p->size++]=BYTE3(c); if (BYTE2(c) != 0) p->buff[p->size++]=BYTE2(c); if (BYTE1(c) != 0) p->buff[p->size++]=BYTE1(c); } #else return getc(fp); #endif return p->buff[--p->size]; } static int ungetc4(int c, FILE *fp) { struct unget_st *p = &ungetbuff[fileno(fp)]; if (p->size >= 4) return EOF; return p->buff[p->size++] = c; } static unsigned char *buffer; static long first, last; static boolean combin_voiced_sound(boolean semi) { int i, mblen; mblen = is_internalUPTEX() ? 3 : 2; if (last-mblen < first) return false; if (multistrlen(buffer,last,last-mblen) != mblen) return false; i = toUCS(fromBUFF(buffer,last,last-mblen)); i = get_voiced_sound(i, semi); if (i == 0) return false; i = toBUFF(fromUCS(i)); if (BYTE2(i) != 0) buffer[last-3] = BYTE2(i); /* always */ buffer[last-2] = BYTE3(i); /* always */ buffer[last-1] = BYTE4(i); return true; }
BOOL vncVideoDriver::CheckVersion() { _ASSERTE(IsWinNT()); HDC l_gdc= ::CreateDC(m_devname, NULL, NULL, NULL); if (!l_gdc) { vnclog.Print( LL_INTERR, VNCLOG("vncVideoDriver::CheckVersion: can't create DC on \"%s\"\n"), m_devname); return FALSE; } Esc_dmf_Qvi_IN qvi_in; qvi_in.cbSize = sizeof(qvi_in); vnclog.Print( LL_INTINFO, "Supported driver version is: min = %u.%u.%u.%u, cur = %u.%u.%u.%u\n", BYTE3(DMF_PROTO_VER_MINCOMPAT), BYTE2(DMF_PROTO_VER_MINCOMPAT), BYTE1(DMF_PROTO_VER_MINCOMPAT), BYTE0(DMF_PROTO_VER_MINCOMPAT), BYTE3(DMF_PROTO_VER_CURRENT), BYTE2(DMF_PROTO_VER_CURRENT), BYTE1(DMF_PROTO_VER_CURRENT), BYTE0(DMF_PROTO_VER_CURRENT)); qvi_in.app_actual_version = DMF_PROTO_VER_CURRENT; qvi_in.display_minreq_version = DMF_PROTO_VER_MINCOMPAT; qvi_in.connect_options = 0; Esc_dmf_Qvi_OUT qvi_out; qvi_out.cbSize = sizeof(qvi_out); int drvCr = ExtEscape( l_gdc, ESC_QVI, sizeof(qvi_in), (LPSTR) &qvi_in, sizeof(qvi_out), (LPSTR) &qvi_out); DeleteDC(l_gdc); if (drvCr == 0) { vnclog.Print( LL_INTERR, VNCLOG("vncVideoDriver::CheckVersion: ESC_QVI not supported by this version of Mirage\n")); return FALSE; } vnclog.Print( LL_INTINFO, "Driver version is: display = %u.%u.%u.%u (build %u)," " miniport = %u.%u.%u.%u (build %u)," " appMinReq = %u.%u.%u.%u\n", BYTE3(qvi_out.display_actual_version), BYTE2(qvi_out.display_actual_version), BYTE1(qvi_out.display_actual_version), BYTE0(qvi_out.display_actual_version), qvi_out.display_buildno, BYTE3(qvi_out.miniport_actual_version), BYTE2(qvi_out.miniport_actual_version), BYTE1(qvi_out.miniport_actual_version), BYTE0(qvi_out.miniport_actual_version), qvi_out.miniport_buildno, BYTE3(qvi_out.app_minreq_version), BYTE2(qvi_out.app_minreq_version), BYTE1(qvi_out.app_minreq_version), BYTE0(qvi_out.app_minreq_version)); if (drvCr < 0) { vnclog.Print( LL_INTERR, VNCLOG("vncVideoDriver::CheckVersion: ESC_QVI call returned 0x%x\n"), drvCr); return FALSE; } m_drv_ver_mj = BYTE3(qvi_out.display_actual_version); m_drv_ver_mn = BYTE2(qvi_out.display_actual_version); return TRUE; }
static FT_Error TA_font_build_TTC_header(FONT* font, FT_Byte** header_buf, FT_ULong* header_len) { SFNT* sfnts = font->sfnts; FT_Long num_sfnts = font->num_sfnts; SFNT_Table* tables = font->tables; FT_ULong num_tables = font->num_tables; FT_ULong TTF_offset; FT_ULong DSIG_offset; FT_Byte* buf; FT_ULong len; FT_Long i; FT_Byte* p; len = (font->have_DSIG ? 24 : 12) + 4 * num_sfnts; buf = (FT_Byte*)malloc(len); if (!buf) return FT_Err_Out_Of_Memory; p = buf; /* TTC ID string */ *(p++) = 't'; *(p++) = 't'; *(p++) = 'c'; *(p++) = 'f'; /* TTC header version */ *(p++) = 0x00; *(p++) = font->have_DSIG ? 0x02 : 0x01; *(p++) = 0x00; *(p++) = 0x00; /* number of subfonts */ *(p++) = BYTE1(num_sfnts); *(p++) = BYTE2(num_sfnts); *(p++) = BYTE3(num_sfnts); *(p++) = BYTE4(num_sfnts); /* the first TTF subfont header immediately follows the TTC header */ TTF_offset = len; /* loop over all subfonts */ for (i = 0; i < num_sfnts; i++) { SFNT* sfnt = &sfnts[i]; FT_ULong l; TA_sfnt_sort_table_info(sfnt, font); /* only get header length */ (void)TA_sfnt_build_TTF_header(sfnt, font, NULL, &l, 0); *(p++) = BYTE1(TTF_offset); *(p++) = BYTE2(TTF_offset); *(p++) = BYTE3(TTF_offset); *(p++) = BYTE4(TTF_offset); TTF_offset += l; } /* the first SFNT table immediately follows the subfont TTF headers */ TA_font_compute_table_offsets(font, TTF_offset); if (font->have_DSIG) { /* DSIG tag */ *(p++) = 'D'; *(p++) = 'S'; *(p++) = 'I'; *(p++) = 'G'; /* DSIG length */ *(p++) = 0x00; *(p++) = 0x00; *(p++) = 0x00; *(p++) = 0x08; /* DSIG offset; in a TTC this is always the last SFNT table */ DSIG_offset = tables[num_tables - 1].offset; *(p++) = BYTE1(DSIG_offset); *(p++) = BYTE2(DSIG_offset); *(p++) = BYTE3(DSIG_offset); *(p++) = BYTE4(DSIG_offset); } *header_buf = buf; *header_len = len; return TA_Err_Ok; }
FT_Error TA_sfnt_build_TTF_header(SFNT* sfnt, FONT* font, FT_Byte** header_buf, FT_ULong* header_len, FT_Int do_complete) { SFNT_Table* tables = font->tables; SFNT_Table_Info* table_infos = sfnt->table_infos; FT_ULong num_table_infos = sfnt->num_table_infos; FT_Byte* buf; FT_ULong len; FT_Byte* table_record; FT_Byte* head_buf = NULL; /* pointer to `head' table */ FT_ULong head_checksum; /* checksum in `head' table */ FT_ULong num_tables_in_header; FT_ULong i; num_tables_in_header = 0; for (i = 0; i < num_table_infos; i++) { /* ignore empty tables */ if (table_infos[i] != MISSING) num_tables_in_header++; } len = 12 + 16 * num_tables_in_header; if (!do_complete) { *header_len = len; return TA_Err_Ok; } buf = (FT_Byte*)malloc(len); if (!buf) return FT_Err_Out_Of_Memory; /* SFNT version */ buf[0] = 0x00; buf[1] = 0x01; buf[2] = 0x00; buf[3] = 0x00; /* number of tables */ buf[4] = HIGH(num_tables_in_header); buf[5] = LOW(num_tables_in_header); /* auxiliary data */ { FT_ULong search_range, entry_selector, range_shift; FT_ULong i, j; for (i = 1, j = 2; j <= num_tables_in_header; i++, j <<= 1) ; entry_selector = i - 1; search_range = 0x10 << entry_selector; range_shift = (num_tables_in_header << 4) - search_range; buf[6] = HIGH(search_range); buf[7] = LOW(search_range); buf[8] = HIGH(entry_selector); buf[9] = LOW(entry_selector); buf[10] = HIGH(range_shift); buf[11] = LOW(range_shift); } /* location of the first table info record */ table_record = &buf[12]; head_checksum = 0; /* loop over all tables */ for (i = 0; i < num_table_infos; i++) { SFNT_Table_Info table_info = table_infos[i]; SFNT_Table* table; /* ignore empty slots */ if (table_info == MISSING) continue; table = &tables[table_info]; if (table->tag == TTAG_head) { FT_ULong date_high; FT_ULong date_low; /* we always reach this IF clause since FreeType would */ /* have aborted already if the `head' table were missing */ head_buf = table->buf; /* reset checksum in `head' table for recalculation */ head_buf[8] = 0x00; head_buf[9] = 0x00; head_buf[10] = 0x00; head_buf[11] = 0x00; /* update modification time */ TA_get_current_time(&date_high, &date_low); head_buf[28] = BYTE1(date_high); head_buf[29] = BYTE2(date_high); head_buf[30] = BYTE3(date_high); head_buf[31] = BYTE4(date_high); head_buf[32] = BYTE1(date_low); head_buf[33] = BYTE2(date_low); head_buf[34] = BYTE3(date_low); head_buf[35] = BYTE4(date_low); table->checksum = TA_table_compute_checksum(table->buf, table->len); } head_checksum += table->checksum; table_record[0] = BYTE1(table->tag); table_record[1] = BYTE2(table->tag); table_record[2] = BYTE3(table->tag); table_record[3] = BYTE4(table->tag); table_record[4] = BYTE1(table->checksum); table_record[5] = BYTE2(table->checksum); table_record[6] = BYTE3(table->checksum); table_record[7] = BYTE4(table->checksum); table_record[8] = BYTE1(table->offset); table_record[9] = BYTE2(table->offset); table_record[10] = BYTE3(table->offset); table_record[11] = BYTE4(table->offset); table_record[12] = BYTE1(table->len); table_record[13] = BYTE2(table->len); table_record[14] = BYTE3(table->len); table_record[15] = BYTE4(table->len); table_record += 16; } /* the font header is complete; compute `head' checksum */ head_checksum += TA_table_compute_checksum(buf, len); head_checksum = 0xB1B0AFBAUL - head_checksum; /* store checksum in `head' table; */ head_buf[8] = BYTE1(head_checksum); head_buf[9] = BYTE2(head_checksum); head_buf[10] = BYTE3(head_checksum); head_buf[11] = BYTE4(head_checksum); *header_buf = buf; *header_len = len; return TA_Err_Ok; }
/* This function handles (ctx->state_count < 32767) */ uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen) { uint32_t i = 0; int matches = 0; uint8_t mpm_bitarray[ctx->mpm_bitarray_size]; memset(mpm_bitarray, 0, ctx->mpm_bitarray_size); const uint8_t* restrict xlate = ctx->translate_table; STYPE *state_table = (STYPE*)ctx->state_table; STYPE state = 0; int c = xlate[buf[0]]; /* If buflen at least 4 bytes and buf 4-byte aligned. */ if (buflen >= (4 + EXTRA) && ((uintptr_t)buf & 0x3) == 0) { BUF_TYPE data = *(BUF_TYPE* restrict)(&buf[0]); uint64_t index = 0; /* Process 4*floor(buflen/4) bytes. */ i = 0; while ((i + EXTRA) < (buflen & ~0x3)) { BUF_TYPE data1 = *(BUF_TYPE* restrict)(&buf[i + 4]); index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE1(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE2(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE3(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } data = data1; i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE0(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; } } /* Process buflen % 4 bytes. */ for (; i < buflen; i++) { size_t index = 0 ; index = SINDEX(index, state); state = SLOAD(state_table + index + c); #ifndef __tile__ if (likely(i+1 < buflen)) #endif c = xlate[buf[i+1]]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } } /* for (i = 0; i < buflen; i++) */ return matches; }
static int checkSCSICommand(void* MSDStatus, usb_device_t* device, uint16_t TransferLength, uint8_t SCSIOpcode) { // CSW Status #ifdef _USB_DIAGNOSIS_ putch('\n'); memshow(MSDStatus,13, false); putch('\n'); #endif int error = 0; // check signature 0x53425355 // DWORD 0 (byte 0:3) uint32_t CSWsignature = *(uint32_t*)MSDStatus; // DWORD 0 if (CSWsignature == CSWMagicOK) { #ifdef _USB_DIAGNOSIS_ textColor(SUCCESS); printf("\nCSW signature OK "); textColor(TEXT); #endif } else if (CSWsignature == CSWMagicNotOK) { textColor(ERROR); printf("\nCSW signature wrong (not processed)"); textColor(TEXT); return -1; } else { textColor(ERROR); printf("\nCSW signature wrong (processed, but wrong value)"); textColor(TEXT); error = -2; } // check matching tag uint32_t CSWtag = *(((uint32_t*)MSDStatus)+1); // DWORD 1 (byte 4:7) if ((BYTE1(CSWtag) == SCSIOpcode) && (BYTE2(CSWtag) == 0x42) && (BYTE3(CSWtag) == 0x42) && (BYTE4(CSWtag) == 0x42)) { #ifdef _USB_DIAGNOSIS_ textColor(SUCCESS); printf("CSW tag %yh OK ",BYTE1(CSWtag)); textColor(TEXT); #endif } else { textColor(ERROR); printf("\nError: CSW tag wrong"); textColor(TEXT); error = -3; } // check CSWDataResidue uint32_t CSWDataResidue = *(((uint32_t*)MSDStatus)+2); // DWORD 2 (byte 8:11) if (CSWDataResidue == 0) { #ifdef _USB_DIAGNOSIS_ textColor(SUCCESS); printf("\tCSW data residue OK "); textColor(TEXT); #endif } else { textColor(0x06); printf("\nCSW data residue: %u", CSWDataResidue); textColor(TEXT); } // check status byte // DWORD 3 (byte 12) uint8_t CSWstatusByte = *(((uint8_t*)MSDStatus)+12); // byte 12 (last byte of 13 bytes) textColor(ERROR); switch (CSWstatusByte) { case 0x00: #ifdef _USB_DIAGNOSIS_ textColor(SUCCESS); printf("\tCSW status OK"); #endif break; case 0x01: printf("\nCommand failed"); error = -4; break; case 0x02: printf("\nPhase Error"); textColor(IMPORTANT); printf("\nReset recovery is needed"); usb_resetRecoveryMSD(device, device->numInterfaceMSD); error = -5; break; default: printf("\nCSW status byte: undefined value (error)"); error = -6; break; } textColor(TEXT); return error; }
static void formatSCSICommand(uint8_t SCSIcommand, struct usb_CommandBlockWrapper* cbw, uint32_t LBA, uint16_t TransferLength) { memset(cbw, 0, sizeof(struct usb_CommandBlockWrapper)); switch (SCSIcommand) { case 0x00: // test unit ready(6) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x42424200; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWFlags = 0x00; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 6; // only bits 4:0 break; case 0x03: // Request Sense(6) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x42424203; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWDataTransferLength = 18; cbw->CBWFlags = 0x80; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 6; // only bits 4:0 cbw->commandByte[0] = 0x03; // Operation code cbw->commandByte[4] = 18; // Allocation length (max. bytes) break; case 0x12: // Inquiry(6) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x42424212; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWDataTransferLength = 36; cbw->CBWFlags = 0x80; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 6; // only bits 4:0 cbw->commandByte[0] = 0x12; // Operation code cbw->commandByte[4] = 36; // Allocation length (max. bytes) break; case 0x25: // read capacity(10) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x42424225; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWDataTransferLength = 8; cbw->CBWFlags = 0x80; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 10; // only bits 4:0 cbw->commandByte[0] = 0x25; // Operation code cbw->commandByte[2] = BYTE4(LBA); // LBA MSB cbw->commandByte[3] = BYTE3(LBA); // LBA cbw->commandByte[4] = BYTE2(LBA); // LBA cbw->commandByte[5] = BYTE1(LBA); // LBA LSB break; case 0x28: // read(10) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x42424228; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWDataTransferLength = TransferLength*512; // byte = 512 * block cbw->CBWFlags = 0x80; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 10; // only bits 4:0 cbw->commandByte[0] = 0x28; // Operation code cbw->commandByte[2] = BYTE4(LBA); // LBA MSB cbw->commandByte[3] = BYTE3(LBA); // LBA cbw->commandByte[4] = BYTE2(LBA); // LBA cbw->commandByte[5] = BYTE1(LBA); // LBA LSB cbw->commandByte[7] = BYTE2(TransferLength); // MSB <--- blocks not byte! cbw->commandByte[8] = BYTE1(TransferLength); // LSB break; case 0x2A: // write(10) cbw->CBWSignature = CBWMagic; // magic cbw->CBWTag = 0x4242422A; // device echoes this field in the CSWTag field of the associated CSW cbw->CBWDataTransferLength = TransferLength*512; // byte = 512 * block cbw->CBWFlags = 0x00; // Out: 0x00 In: 0x80 cbw->CBWCBLength = 10; // only bits 4:0 cbw->commandByte[0] = 0x2A; // Operation code cbw->commandByte[2] = BYTE4(LBA); // LBA MSB cbw->commandByte[3] = BYTE3(LBA); // LBA cbw->commandByte[4] = BYTE2(LBA); // LBA cbw->commandByte[5] = BYTE1(LBA); // LBA LSB cbw->commandByte[7] = BYTE2(TransferLength); // MSB <--- blocks not byte! cbw->commandByte[8] = BYTE1(TransferLength); // LSB break; } }
LONG CMirageManager::SetupDriver(CRegKey& regKeyDevice, DISPLAY_DEVICE& deviceInfo, Esc_dmf_Qvi_OUT& qvi_out) { DFEXT_DEVMODE deviceMode; memset(&deviceMode, 0, sizeof(deviceMode)); deviceMode.dmSize = sizeof(DEVMODE); WORD drvExtraSaved = deviceMode.dmDriverExtra; memset(&deviceMode, 0, sizeof(DEVMODE)); deviceMode.dmSize = sizeof(DEVMODE); deviceMode.dmDriverExtra = drvExtraSaved; POINTL pos; pos.x = pos.y = 0; deviceMode.dmPelsWidth = 100; deviceMode.dmPelsHeight = 100; deviceMode.dmBitsPerPel = 32; deviceMode.dmPosition = pos; deviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION; deviceMode.dmDeviceName[0] = '\0'; CMirageManager::WriteDiagnostics(_T("Attaching to desktop")); LONG retval = regKeyDevice.SetDWORDValue(_T("Attach.ToDesktop"), true); if (ERROR_SUCCESS != retval) { CMirageManager::WriteDiagnostics(_T("Failed to attach to desktop")); return retval; } CMirageManager::WriteDiagnostics(_T("Committing display changes")); retval = CMirageManager::CommitDisplayChanges(&deviceMode, deviceInfo); if (ERROR_SUCCESS != retval) { CMirageManager::WriteDiagnostics(_T("Failed to commit display changes")); return retval; } CMirageManager::WriteDiagnostics(_T("Creating device context")); HDC driverDC; driverDC = CreateDC(deviceInfo.DeviceName, NULL, NULL, NULL); if (!driverDC) { CMirageManager::WriteDiagnostics(_T("Failed to create device context")); return ERROR_DC_NOT_FOUND; } CMirageManager::WriteDiagnostics(_T("Querying Driver Version")); Esc_dmf_Qvi_IN qvi_in; qvi_in.cbSize = sizeof(qvi_in); qvi_in.app_actual_version = DMF_PROTO_VER_CURRENT; qvi_in.display_minreq_version = DMF_PROTO_VER_MINCOMPAT; qvi_in.connect_options = 0; qvi_out.cbSize = sizeof(qvi_out); ExtEscape(driverDC, ESC_QVI, sizeof(qvi_in), (LPSTR) &qvi_in, sizeof(qvi_out), (LPSTR) &qvi_out); std::wstringstream driverVersion(_T("")); driverVersion << _T("Driver Version : ") << BYTE3(qvi_out.display_actual_version) << _T(".") << BYTE2(qvi_out.display_actual_version) << _T(".") << BYTE1(qvi_out.display_actual_version) << _T(".") << BYTE0(qvi_out.display_actual_version) << _T(" build(") << qvi_out.display_buildno << _T(")"); CMirageManager::WriteDiagnostics(driverVersion.str()); if (driverDC) { CMirageManager::WriteDiagnostics(_T("Deleting device context")); ::DeleteDC(driverDC); driverDC = NULL; } CMirageManager::WriteDiagnostics(_T("Detaching from desktop")); retval = regKeyDevice.SetDWORDValue(_T("Attach.ToDesktop"), false); if (ERROR_SUCCESS != retval) return retval; deviceMode.dmPelsWidth = 0; deviceMode.dmPelsHeight = 0; OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(osvi); GetVersionEx(&osvi); DEVMODE* pdm = NULL; if (osvi.dwMajorVersion > 5 || (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion > 0)) pdm = &deviceMode; CMirageManager::WriteDiagnostics(_T("Committing display changes")); retval = CommitDisplayChanges(pdm, deviceInfo); if (ERROR_SUCCESS != retval) return retval; return ERROR_SUCCESS; }