/* Manufacturer & Product name check. * 名前チェック : 成功=1 失敗=0 読み取り不能=(-1) */ static int check_product_string( HANDLE handle, const char* const my_manufacturer, const char* const my_product ) { unsigned short unicode[512]; char string1[256]; char string2[256]; if( !HidD_GetManufacturerString( handle, unicode, sizeof(unicode) ) ) { return -1; } uni_to_string( string1, unicode ); if( !HidD_GetProductString( handle, unicode, sizeof(unicode) ) ) { return -1; } uni_to_string( string2, unicode ); #if DUMP_PRODUCT fprintf( stderr, "iManufacturer:%s\n", string1 ); fprintf( stderr, "iProduct:%s\n", string2 ); #endif if( strcmp( string1, my_manufacturer) != 0 ) { return 0; } if( strcmp( string2, my_product ) != 0 ) { return 0; } return 1; //合致した. }
/* Manufacturer & Product name check. * 名前チェック : 成功=1 失敗=0 読み取り不能=(-1) */ static int check_product_string(HANDLE handle, const char *serial) { unsigned short unicode[BUFF_SIZE*2]; char string1[BUFF_SIZE]; char string2[BUFF_SIZE]; char string3[BUFF_SIZE]; if (!HidD_GetManufacturerString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string1, unicode); if (!HidD_GetProductString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string2, unicode); if (!HidD_GetSerialNumberString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string3, unicode); if (serial[0]=='*') { fprintf(stderr, "Manufacturer: [%6s], Product: [%7s], serial number: [%s]\n", string1, string2, string3); } #ifdef MY_Manufacturer if (strcmp(string1, MY_Manufacturer) != 0) return 0; // 一致せず #endif #ifdef MY_Product if (strcmp(string2, MY_Product) != 0) return 0; // 一致せず #endif found_hidaspx++; if (strcmp(string3, serial) != 0) return 0; // 一致せず return 1; //合致した. }
/* Manufacturer & Product name check. * 名前チェック : 成功=1 失敗=0 読み取り不能=(-1) */ static int check_product_string(HANDLE handle, const char *serial, int list_mode) { static int first = 1; int i; unsigned short unicode[BUFF_SIZE*2]; char string1[BUFF_SIZE]; char string2[BUFF_SIZE]; char string3[BUFF_SIZE]; char tmp[2][BUFF_SIZE]; #if DEBUG list_mode = 1; #endif Sleep(20); if (!HidD_GetManufacturerString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string1, unicode); Sleep(20); if (!HidD_GetProductString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string2, unicode); // シリアル番号のチェックを厳密化 (2010/02/12 13:24:08) if (serial[0]=='*') { #define f_auto_retry 3 /* for HIDaspx (Auto detect, Retry MAX) */ for (i=0; i<f_auto_retry; i++) { Sleep(20); if (!HidD_GetSerialNumberString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(tmp[i%2], unicode); if ((i>0) && ((i%2) == 1)) { if (strcmp(tmp[0], tmp[1])==0) { strcpy(string3, tmp[0]); // OK } else { return -1; } } } if (list_mode) { if (first) { fprintf(stderr, "VID=%04x, PID=%04x, [%s], [%s], serial=[%s] (*)\n", MY_VID, MY_PID, string1, string2, string3); first = 0; } else { fprintf(stderr, "VID=%04x, PID=%04x, [%s], [%s], serial=[%s]\n", MY_VID, MY_PID, string1, string2, string3); } } } else { Sleep(20); if (!HidD_GetSerialNumberString(handle, unicode, sizeof(unicode))) { return -1; } uni_to_string(string3, unicode); } #ifdef MY_Manufacturer if (strcmp(string1, MY_Manufacturer) != 0) return 0; // 一致せず #endif #ifdef MY_Product if (strcmp(string2, MY_Product) != 0) return 0; // 一致せず #endif found_hidaspx++; /* Check serial number */ if (found_hidaspx) { if (strcmp(string3, serial) == 0) return 1; //合致した. else if (strcmp(serial ,"*") == 0) return 1; //合致した. } return 0; // 一致せず }