static void dumpRegs(struct ft5x06_ts *ts, unsigned start, unsigned end) { u8 regbuf[512]; unsigned char startch[1] = { start }; int ret ; struct i2c_msg readpkt[2] = { {ts->client->addr, 0, 1, startch}, {ts->client->addr, I2C_M_RD, end-start+1, regbuf} }; ret = i2c_transfer(ts->client->adapter, readpkt, ARRAY_SIZE(readpkt)); if (ret != ARRAY_SIZE(readpkt)) { printk(KERN_WARNING "%s: i2c_transfer failed\n", client_name); } else { printk(KERN_ERR "registers %02x..%02x\n", start, end); printHex(regbuf, end-start+1); } }
void cmd_peep(void) { int i=0; while (i <= ENDEEPROM) { if (!(i&63)) {speol(); printHex(i+0xe000); spb(':'); } if (!(i&7)) spb(' '); if (!(i&3)) spb(' '); byte c = eeread(i) & 0xff; if (c == 0) spb('\\'); //else if ((c == 255) || (c < 0)) spb('.'); else if (c == 255) spb('.'); else if (c < ' ') spb('^'); else spb(c); i++; } speol(); }
static cgmi_Status cgmiTestUserDataBufferCB(void *pUserData, void *pBuffer) { #if GST_CHECK_VERSION(1,0,0) GstMapInfo map; #endif GstBuffer *pGstBuff = (GstBuffer *)pBuffer; guint8 *bufferData; guint bufferSize; if( NULL == pGstBuff ) { return CGMI_ERROR_BAD_PARAM; } #if GST_CHECK_VERSION(1,0,0) if ( gst_buffer_map(pGstBuff, &map, GST_MAP_READ) == FALSE ) { g_print("Failed in mapping buffer for reading userdata!\n"); return CGMI_ERROR_FAILED; } bufferData = map.data; bufferSize = map.size; #else bufferData = GST_BUFFER_DATA( pGstBuff ); bufferSize = GST_BUFFER_SIZE( pGstBuff ); #endif // Dump data recieved. g_print("cgmiTestUserDataBufferCB called with buffer of size (%d)...\n", bufferSize); printHex( bufferData, bufferSize ); g_print("\n"); #if GST_CHECK_VERSION(1,0,0) gst_buffer_unmap( pGstBuff, &map ); #endif // Free buffer gst_buffer_unref( pGstBuff ); gUserDataCbCalled++; return CGMI_ERROR_SUCCESS; }
// Update Time State trigger // Only valid with Sleep/Resume and Inactive/Active triggers // States: // * 0x00 - Off // * 0x01 - Activate // * 0x02 - On // * 0x03 - Deactivate void Macro_timeState( uint8_t type, uint16_t cur_time, uint8_t state ) { // Make sure this is a valid trigger type switch ( type ) { case TriggerType_Sleep1: case TriggerType_Resume1: case TriggerType_Inactive1: case TriggerType_Active1: break; // Ignore if not the correct type default: warn_msg("Invalid time state trigger update: "); printHex( type ); print(NL); return; } // cur_time is controlled by the caller // When this function called the trigger is active if ( cur_time > 0xFF ) { warn_msg("Only 255 time instances are accepted for a time state trigger: "); printInt16( cur_time ); print(NL); return; } uint8_t index = cur_time; // Only add to macro trigger list if one of three states switch ( state ) { case ScheduleType_A: // Activate case ScheduleType_On: // On case ScheduleType_D: // Deactivate macroTriggerEventBuffer[ macroTriggerEventBufferSize ].index = index; macroTriggerEventBuffer[ macroTriggerEventBufferSize ].state = state; macroTriggerEventBuffer[ macroTriggerEventBufferSize ].type = type; macroTriggerEventBufferSize++; break; } }
static cgmi_Status cgmi_SectionBufferCallback_PMT( void *pUserData, void *pFilterPriv, void *pFilterId, cgmi_Status sectionStatus, char *pSection, int sectionSize) { cgmi_Status retStat; tMpegTsPmt curPmt; //g_print( "cgmi_QueryBufferCallback -- pFilterId: 0x%08lx \n", pFilterId ); if( NULL == pSection ) { g_print("NULL buffer passed to cgmiSectionBufferCallback.\n"); return CGMI_ERROR_BAD_PARAM; } g_print("Received section pFilterId: %p, sectionSize %d\n\n", pFilterId, sectionSize); printHex( pSection, sectionSize ); g_print("\n\n"); parsePMT( &curPmt, pSection, sectionSize ); printPMT( &curPmt ); gPmtParsed = true; g_print("Calling cgmi_StopSectionFilter...\n"); retStat = cgmi_StopSectionFilter( pFilterPriv, pFilterId ); CHECK_ERROR(retStat); /* g_print("Calling cgmi_DestroySectionFilter...\n"); retStat = cgmi_DestroySectionFilter( pFilterPriv, pFilterId ); CHECK_ERROR(retStat); */ // Free buffer allocated in cgmi_QueryBufferCallback g_free( pSection ); return CGMI_ERROR_SUCCESS; }
int wmain(int argc, wchar_t * argv[]) { RPC_BINDING_HANDLE hBinding; wchar_t dataIn[] = L"a cleartext message!"; PVOID pDataOut, pDataOut2; DWORD dwDataOut, dwDataOut2; if(argc > 1) { wprintf(L"Will use \'%s\' for DC name...\n", argv[1]); if(kull_m_rpc_createBinding(L"ncacn_np", argv[1], L"\\pipe\\protected_storage", L"ProtectedStorage", RPC_C_IMP_LEVEL_IMPERSONATE, &hBinding, NULL)) { wprintf(L"\n* Retrieve RSA Public Key\n"); if(kull_m_rpc_bkrp_generic(&hBinding, &BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID, (PVOID) 0xbadc00fe, 0, &pDataOut, &dwDataOut)) // don't ask me why dummy data is needed here (not used). { wprintf(L" > pDataOut @ 0x%p (%u)\n", pDataOut, dwDataOut); //printHex(pDataOut, dwDataOut); MIDL_user_free(pDataOut); } wprintf(L"\n* Backup a secret (%s)\n", dataIn); if(kull_m_rpc_bkrp_generic(&hBinding, &BACKUPKEY_BACKUP_GUID, &dataIn, sizeof(dataIn), &pDataOut, &dwDataOut)) { wprintf(L" > pDataOut @ 0x%p (%u)\n", pDataOut, dwDataOut); printHex(pDataOut, dwDataOut); wprintf(L"\n* Restore a secret\n"); if(kull_m_rpc_bkrp_generic(&hBinding, &BACKUPKEY_RESTORE_GUID, pDataOut, dwDataOut, &pDataOut2, &dwDataOut2)) { wprintf(L" > pDataOut2 @ 0x%p (%u)\n", pDataOut, dwDataOut); wprintf(L" > Secret : %s\n", pDataOut2); MIDL_user_free(pDataOut2); } MIDL_user_free(pDataOut); } kull_m_rpc_deleteBinding(&hBinding); } } else wprintf(L"[ERROR] A DC name is needed in argument\n"); return ERROR_SUCCESS; }
unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const uint8_t *spData) { unsigned char status = 0; unsigned short offset = 0; unsigned char* spDataPtr = (unsigned char*)spData; uint8_t rambuffer[SP_PORTION_SIZE]; while ((status == 0) && (spLength >= SP_PORTION_SIZE)) { for (uint8_t i=0; i<SP_PORTION_SIZE; i++) { rambuffer[i] = pgm_read_byte(spData + i + offset); } #if (DEBUG_MODE == 1) PRINT_F("Writing: "); printDec16(offset); PRINT_F("\t"); for (uint8_t i=0; i<SP_PORTION_SIZE; i++) { PRINT_F("0x"); printHex(rambuffer[i]); PRINT_F(", "); } PRINT_F("\n\r"); #endif status = nvmem_write(ulFileId, SP_PORTION_SIZE, offset, rambuffer); offset += SP_PORTION_SIZE; spLength -= SP_PORTION_SIZE; spDataPtr += SP_PORTION_SIZE; } if (status !=0) { // NVMEM error occurred return status; } if (spLength != 0) { memcpy_P(rambuffer, spDataPtr, SP_PORTION_SIZE); // if reached here, a reminder is left status = nvmem_write(ulFileId, spLength, offset, rambuffer); } return status; }
UINT8 nvmem_write_patch(UINT32 ulFileId, UINT32 spLength, const UINT8 *spData) { UINT8 status = 0; UINT16 offset = 0; UINT8* spDataPtr = (UINT8*)spData; UINT8 rambuffer[SP_PORTION_SIZE]; while ((status == 0) && (spLength >= SP_PORTION_SIZE)) { for (UINT8 i=0; i<SP_PORTION_SIZE; i++) { rambuffer[i] = pgm_read_byte(spData + i + offset); } #if (DEBUG_MODE == 1) PRINT_F("Writing: "); printDec16(offset); PRINT_F("\t"); for (UINT8 i=0; i<SP_PORTION_SIZE; i++) { PRINT_F("0x"); printHex(rambuffer[i]); PRINT_F(", "); } PRINT_F("\n\r"); #endif status = nvmem_write(ulFileId, SP_PORTION_SIZE, offset, rambuffer); offset += SP_PORTION_SIZE; spLength -= SP_PORTION_SIZE; spDataPtr += SP_PORTION_SIZE; } if (status !=0) { // NVMEM error occurred return status; } if (spLength != 0) { memcpy_P(rambuffer, spDataPtr, SP_PORTION_SIZE); // if reached here, a reminder is left status = nvmem_write(ulFileId, spLength, offset, rambuffer); } return status; }
/* **----------------------------------------------------------------------------- ** ** Abstract: ** This function selects according to which type of element to print ** the function to send the data via UART. A new line character is added ** ** Parameters: ** string: data to be sent via UART ** typeString: selects whether it is string, decimal or hex ** ** Returns: ** True: Successful UART transmission ** False: Unsuccessful UART transmission ** **----------------------------------------------------------------------------- */ bool selectPrintln(uint8_t * string, uint8_t typeString) { bool result = false; switch(typeString){ case TYPE_STRING: result = printString(string, WITH_LINE); break; case TYPE_HEX: result = printHex((uint8_t)string, WITH_LINE); break; case TYPE_DEC: result = printDec((uint8_t)string, WITH_LINE); break; default: break; } return result; }
void syscallHandler(uint32_t eax, uint32_t ebx){ switch(eax){ case 0: ;char c = (char)ebx; putch(c); break; case 1: ;char* c2 = (char*)ebx; print(c2); break; case 2: __kill__(); break; default: print("Other syscall "); printHex(eax); println(""); break; } }
/** Transmit a packet with checksum to the SM130. */ void SM130::transmitData() { // wait until at least 20ms passed since last I2C transmission while(t > millis()); t = millis() + 20; // init checksum and packet length byte sum = 0; byte len = data[0] + 1; // remember which command was sent cmd = data[1]; // transmit packet with checksum //Wire.beginTransmission(address); for (int i = 0; i < len; i++) { #if defined(ARDUINO) && ARDUINO >= 100 Wire.write(data[i]); #else Wire.send(data[i]); #endif sum += data[i]; } #if defined(ARDUINO) && ARDUINO >= 100 Wire.write(sum); #else Wire.send(sum); #endif Wire.endTransmission(); // show transmitted packet for debugging if (debug) { Serial.print("> "); printArrayHex(data, len); Serial.print(' '); printHex(sum); Serial.println(); } }
void printHex(Print& p, const uint8_t* buf, size_t len, const __FlashStringHelper* byte_sep, const __FlashStringHelper* group_sep, size_t group_by) { size_t cur_group = 0; while (len--) { // Print the group separator whenever starting a new // group if (group_by && group_sep && cur_group == group_by) { p.print(group_sep); cur_group = 0; } // Print the byte separator, except when at the start of // a new group (this also excludes the first byte) if (cur_group != 0 && byte_sep) p.print(byte_sep); printHex(p, *buf); buf++; cur_group++; } }
void fail() // segfault generation { // int *p = 0x00000000; // p[0] = 13; const int _m_size = 25; char * _m_array; // _m_array = new int [_m_size]; _m_array = new char[_m_size]; for (int i = 0; i<_m_size; i++) { //int a=rand() % my_array.size(); _m_array[i] = rand() % _m_size; cout << i << " - " << _m_array[i]; printHex(_m_array[i]); // cout << "\n"; } cout << endl; delete [] _m_array; }
void printData( const char *label, CFDataRef data, PrintDataType whichType, OidParser &parser) { const unsigned char *buf = CFDataGetBytePtr(data); unsigned len = CFDataGetLength(data); printf("%s: ", label); switch(whichType) { case PD_Hex: printHex(buf, len, 16); break; case PD_ASCII: printAscii((const char *)buf, len, 50); break; case PD_OID: printOid(buf, len, parser); } putchar('\n'); }
bool EmbitLoRaModem::Send(LoRaPacket* packet, bool ack) { unsigned char length = packet->Write(sendBuffer); PRINTLN("Sending payload: "); for (unsigned char i = 0; i < length; i++) { printHex(sendBuffer[i]); } PRINTLN(); if(ack == true) SendPacket(CMD_SEND_PREFIX, sizeof(CMD_SEND_PREFIX), sendBuffer, length); else SendPacket(CMD_SEND_PREFIX_NO_ACK, sizeof(CMD_SEND_PREFIX_NO_ACK), sendBuffer, length); unsigned char result = ReadPacket(3); if(result != 0){ PRINTLN("Failed to send packet"); return false; } else return true; }
signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, unsigned char *buff) { long iRes; unsigned char *ptr; unsigned char *args; iRes = EFAIL; ptr = tSLInformation.pucTxCommandBuffer; args = (ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE); // Fill in HCI packet structure args = UINT32_TO_STREAM(args, ulFileId); args = UINT32_TO_STREAM(args, 12); args = UINT32_TO_STREAM(args, ulLength); args = UINT32_TO_STREAM(args, ulEntryOffset); memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE + NVMEM_WRITE_PARAMS_LEN),buff,ulLength); #if (DEBUG_MODE == 1) PRINT_F("Writing:\t"); for (uint8_t i=0; i<ulLength; i++) { PRINT_F("0x"); printHex(buff[i]); PRINT_F(", "); } PRINT_F("\n\r"); #endif // Initiate a HCI command but it will come on data channel hci_data_command_send(HCI_CMND_NVMEM_WRITE, ptr, NVMEM_WRITE_PARAMS_LEN, ulLength); SimpleLinkWaitEvent(HCI_EVNT_NVMEM_WRITE, &iRes); return(iRes); }
int SignCreate(RSA *privkey, char *data, int dataLen, char *signature, int *signature_len) { unsigned int signLen = 0; int ret = 0; char *buf = NULL; char *hash =(char *) malloc(SHA512_DIGEST_LENGTH); if (hash != NULL) { SHA512((const unsigned char *)data, dataLen, (unsigned char *)hash); ret = RSA_sign(NID_sha512, (const unsigned char *)hash, SHA512_DIGEST_LENGTH, (unsigned char *)signature, &signLen, privkey); if (ret == 1) { printHex("SIGNATURE", (const unsigned char *)signature, signLen); *signature_len = signLen; ret = 1; } free(hash); } return ret; }
void bunny24_bruteForce(bit plain[block_length] , bit crypt[block_length]){ unsigned int i, end = 1024 * 1024 * 16; bit test[block_length]; bit testp[block_length]; for(i = 0; i < end; i++) { arrayCopy(plain , testp , 24); int j; for(j = 0; j < 24; j++) { if(i & (1 << j)) test[j] = 1; else test[j] = 0; } //printArray(test , 24); bunny24_encrypt(testp , test); if(arrayEqual(testp , crypt , 24) == 0) { printHex(test , 24); return; } //printf("fail key %d \n " , i); } }
// Detect short or open circuit in Matrix // Only works with IS31FL3733 void LED_shortOpenDetect() { #if ISSI_Chip_31FL3733_define == 1 || ISSI_Chip_31FL3736_define == 1 // Pause ISSI processing LED_pause = 1; for ( uint8_t ch = 0; ch < ISSI_Chips_define; ch++ ) { uint8_t addr = LED_ChannelMapping[ ch ].addr; uint8_t bus = LED_ChannelMapping[ ch ].bus; // Set Global Current Control (needed for accurate reading) LED_writeReg( bus, addr, 0x01, 0x01, ISSI_ConfigPage ); // Enable master sync for the first chip and disable software shutdown // Also enable OSD (Open/Short Detect) if ( ch == 0 ) { LED_writeReg( bus, addr, 0x00, 0x45, ISSI_ConfigPage ); } // Slave sync for the rest and disable software shutdown // Also enable OSD (Open/Short Detect) else { LED_writeReg( bus, addr, 0x00, 0x85, ISSI_ConfigPage ); } // Wait for 3.3 ms before reading the value // Needs at least 3.264 ms to query the information delay_us(3300); // Read registers info_msg("Bus: "); printHex( bus ); print(" Addr: "); printHex( addr ); print(" - 0x18 -> 0x2F + 0x30 -> 0x47"); print(NL); // Validate open detection // TODO for ( uint8_t reg = 0x18; reg < 0x30; reg++ ) { uint8_t val = LED_readReg( bus, addr, reg, ISSI_LEDControlPage ); printHex_op( val, 2 ); print(" "); } print(NL); // Validate short detection // TODO for ( uint8_t reg = 0x30; reg < 0x48; reg++ ) { uint8_t val = LED_readReg( bus, addr, reg, ISSI_LEDControlPage ); printHex_op( val, 2 ); print(" "); } print(NL); } // We have to adjust various settings in order to get the correct reading // Reset ISSI configuration LED_reset(); #endif }
void Connect_rx_process( uint8_t uartNum ) { // Determine current position to read until uint16_t bufpos = 0; switch ( uartNum ) { DMA_BUF_POS( 0, bufpos ); DMA_BUF_POS( 1, bufpos ); } // Process each of the new bytes // Even if we receive more bytes during processing, wait until the next check so we don't starve other tasks while ( bufpos != uart_rx_buf[ uartNum ].last_read ) { // If the last_read byte is at the buffer edge, roll back to beginning if ( uart_rx_buf[ uartNum ].last_read == 0 ) { uart_rx_buf[ uartNum ].last_read = UART_Buffer_Size; // Check to see if we're at the boundary if ( bufpos == UART_Buffer_Size ) break; } // Read the byte out of Rx DMA buffer uint8_t byte = uart_rx_buf[ uartNum ].buffer[ UART_Buffer_Size - uart_rx_buf[ uartNum ].last_read-- ]; if ( Connect_debug ) { printHex( byte ); print(" "); } // Process UART byte switch ( uart_rx_status[ uartNum ].status ) { // Every packet must start with a SYN / 0x16 case UARTStatus_Wait: if ( Connect_debug ) { print(" Wait "); } uart_rx_status[ uartNum ].status = byte == 0x16 ? UARTStatus_SYN : UARTStatus_Wait; break; // After a SYN, there must be a SOH / 0x01 case UARTStatus_SYN: if ( Connect_debug ) { print(" SYN "); } uart_rx_status[ uartNum ].status = byte == 0x01 ? UARTStatus_SOH : UARTStatus_Wait; break; // After a SOH the packet structure may diverge a bit // This is the packet type field (refer to the Command enum) // For very small packets (e.g. IdRequest) this is all that's required to take action case UARTStatus_SOH: { if ( Connect_debug ) { print(" SOH "); } // Check if this is actually a reserved CMD 0x16 (Error condition) if ( byte == Command_SYN ) { uart_rx_status[ uartNum ].status = UARTStatus_SYN; break; } // Otherwise process the command if ( byte < Command_TOP ) { uart_rx_status[ uartNum ].status = UARTStatus_Command; uart_rx_status[ uartNum ].command = byte; uart_rx_status[ uartNum ].bytes_waiting = 0xFFFF; } // Invalid packet type, ignore else { uart_rx_status[ uartNum ].status = UARTStatus_Wait; } // Check if this is a very short packet switch ( uart_rx_status[ uartNum ].command ) { case IdRequest: Connect_receive_IdRequest( 0, (uint16_t*)&uart_rx_status[ uartNum ].bytes_waiting, uartNum ); uart_rx_status[ uartNum ].status = UARTStatus_Wait; break; default: if ( Connect_debug ) { print(" ### "); printHex( uart_rx_status[ uartNum ].command ); } break; } break; } // After the packet type has been deciphered do Command specific processing // Until the Command has received all the bytes it requires the UART buffer stays in this state case UARTStatus_Command: { if ( Connect_debug ) { print(" CMD "); } /* Call specific UARTConnect command receive function */ uint8_t (*rcvFunc)(uint8_t, uint16_t(*), uint8_t) = (uint8_t(*)(uint8_t, uint16_t(*), uint8_t))(Connect_receiveFunctions[ uart_rx_status[ uartNum ].command ]); if ( rcvFunc( byte, (uint16_t*)&uart_rx_status[ uartNum ].bytes_waiting, uartNum ) ) uart_rx_status[ uartNum ].status = UARTStatus_Wait; break; } // Unknown status, should never get here default: erro_msg("Invalid UARTStatus..."); uart_rx_status[ uartNum ].status = UARTStatus_Wait; continue; } if ( Connect_debug ) { print( NL ); } } }
uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t uart_num ) { // Check the directionality if ( uart_num == UART_Master ) { erro_print("Invalid ScanCode direction..."); } // Master node, trigger scan codes if ( Connect_master ) switch ( (*pending_bytes)-- ) { // Byte count always starts at 0xFFFF case 0xFFFF: // Device Id Connect_receive_ScanCodeDeviceId = byte; break; case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) *pending_bytes = byte * sizeof( TriggerGuide ); Connect_receive_ScanCodeBufferPos = 0; break; default: // Set the specific TriggerGuide entry ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte; // Reset the BufferPos if higher than sizeof TriggerGuide // And send the TriggerGuide to the Macro Module if ( Connect_receive_ScanCodeBufferPos >= sizeof( TriggerGuide ) ) { Connect_receive_ScanCodeBufferPos = 0; // Adjust ScanCode offset if ( Connect_receive_ScanCodeDeviceId > 0 ) { // Check if this node is too large if ( Connect_receive_ScanCodeDeviceId >= InterconnectNodeMax ) { warn_msg("Not enough interconnect layout nodes configured: "); printHex( Connect_receive_ScanCodeDeviceId ); print( NL ); break; } // This variable is in generatedKeymaps.h extern uint8_t InterconnectOffsetList[]; Connect_receive_ScanCodeBuffer.scanCode = Connect_receive_ScanCodeBuffer.scanCode + InterconnectOffsetList[ Connect_receive_ScanCodeDeviceId - 1 ]; } // ScanCode receive debug if ( Connect_debug ) { dbug_msg(""); printHex( Connect_receive_ScanCodeBuffer.type ); print(" "); printHex( Connect_receive_ScanCodeBuffer.state ); print(" "); printHex( Connect_receive_ScanCodeBuffer.scanCode ); print( NL ); } // Send ScanCode to macro module Macro_interconnectAdd( &Connect_receive_ScanCodeBuffer ); } break; } // Propagate ScanCode packet // XXX It would be safer to buffer the scancodes first, before transmitting the packet -Jacob // The current method is the more efficient/aggressive, but could cause issues if there were errors during transmission else switch ( (*pending_bytes)-- ) { // Byte count always starts at 0xFFFF case 0xFFFF: // Device Id { Connect_receive_ScanCodeDeviceId = byte; // Lock the master Tx buffer uart_lockTx( UART_Master ); // Send header + Id byte uint8_t header[] = { 0x16, 0x01, ScanCode, byte }; Connect_addBytes( header, sizeof( header ), UART_Master ); break; } case 0xFFFE: // Number of TriggerGuides in bytes *pending_bytes = byte * sizeof( TriggerGuide ); Connect_receive_ScanCodeBufferPos = 0; // Pass through byte Connect_addBytes( &byte, 1, UART_Master ); break; default: // Pass through byte Connect_addBytes( &byte, 1, UART_Master ); // Unlock Tx Buffer after sending last byte if ( *pending_bytes == 0 ) uart_unlockTx( UART_Master ); break; } // Check whether the scan codes have finished sending return *pending_bytes == 0 ? 1 : 0; }
uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t uart_num ) { // Check if this is the first byte if ( *pending_bytes == 0xFFFF ) { *pending_bytes = byte; if ( Connect_debug ) { dbug_msg("PENDING SET -> "); printHex( byte ); print(" "); printHex( *pending_bytes ); print( NL ); } } // Verify byte else { (*pending_bytes)--; // The argument bytes are always 0xD2 (11010010) if ( byte != 0xD2 ) { warn_print("Cable Fault!"); // Check which side of the chain if ( uart_num == UART_Slave ) { Connect_cableFaultsSlave++; Connect_cableOkSlave = 0; print(" Slave "); } else { Connect_cableFaultsMaster++; Connect_cableOkMaster = 0; print(" Master "); } printHex( byte ); print( NL ); // Signal that the command should wait for a SYN again return 1; } else { // Check which side of the chain if ( uart_num == UART_Slave ) { Connect_cableChecksSlave++; } else { Connect_cableChecksMaster++; } } } // If cable check was successful, set cable ok if ( *pending_bytes == 0 ) { if ( uart_num == UART_Slave ) { Connect_cableOkSlave = 1; } else { Connect_cableOkMaster = 1; } } if ( Connect_debug ) { dbug_msg("CABLECHECK RECEIVE - "); printHex( byte ); print(" "); printHex( *pending_bytes ); print( NL ); } // Check whether the cable check has finished return *pending_bytes == 0 ? 1 : 0; }
// send the contents of keyboard_keys and keyboard_modifier_keys void usb_keyboard_send() { uint32_t wait_count = 0; usb_packet_t *tx_packet; // Wait till ready while ( 1 ) { if ( !usb_configuration ) { erro_print("USB not configured..."); return; } if ( USBKeys_Protocol == 0 ) // Boot Mode { if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) { tx_packet = usb_malloc(); if ( tx_packet ) break; } } else if ( USBKeys_Protocol == 1 ) // NKRO Mode { if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) { tx_packet = usb_malloc(); if ( tx_packet ) break; } } if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) { transmit_previous_timeout = 1; warn_print("USB Transmit Timeout..."); return; } yield(); } // Pointer to USB tx packet buffer uint8_t *tx_buf = tx_packet->buf; switch ( USBKeys_Protocol ) { // Send boot keyboard interrupt packet(s) case 0: // USB Boot Mode debug output if ( Output_DebugMode ) { dbug_msg("Boot USB: "); printHex_op( USBKeys_Modifiers, 2 ); print(" "); printHex( 0 ); print(" "); printHex_op( USBKeys_Keys[0], 2 ); printHex_op( USBKeys_Keys[1], 2 ); printHex_op( USBKeys_Keys[2], 2 ); printHex_op( USBKeys_Keys[3], 2 ); printHex_op( USBKeys_Keys[4], 2 ); printHex_op( USBKeys_Keys[5], 2 ); print( NL ); } // Boot Mode *tx_buf++ = USBKeys_Modifiers; *tx_buf++ = 0; memcpy( tx_buf, USBKeys_Keys, USB_BOOT_MAX_KEYS ); tx_packet->len = 8; // Send USB Packet usb_tx( KEYBOARD_ENDPOINT, tx_packet ); USBKeys_Changed = USBKeyChangeState_None; break; // Send NKRO keyboard interrupts packet(s) case 1: if ( Output_DebugMode ) { dbug_msg("NKRO USB: "); } // Check system control keys if ( USBKeys_Changed & USBKeyChangeState_System ) { if ( Output_DebugMode ) { print("SysCtrl["); printHex_op( USBKeys_SysCtrl, 2 ); print( "] " NL ); } *tx_buf++ = 0x02; // ID *tx_buf = USBKeys_SysCtrl; tx_packet->len = 2; // Send USB Packet usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent } // Check consumer control keys if ( USBKeys_Changed & USBKeyChangeState_Consumer ) { if ( Output_DebugMode ) { print("ConsCtrl["); printHex_op( USBKeys_ConsCtrl, 2 ); print( "] " NL ); } *tx_buf++ = 0x03; // ID *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF); *tx_buf = (uint8_t)(USBKeys_ConsCtrl >> 8); tx_packet->len = 3; // Send USB Packet usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent } // Standard HID Keyboard if ( USBKeys_Changed ) { // USB NKRO Debug output if ( Output_DebugMode ) { printHex_op( USBKeys_Modifiers, 2 ); print(" "); for ( uint8_t c = 0; c < 6; c++ ) printHex_op( USBKeys_Keys[ c ], 2 ); print(" "); for ( uint8_t c = 6; c < 20; c++ ) printHex_op( USBKeys_Keys[ c ], 2 ); print(" "); printHex_op( USBKeys_Keys[20], 2 ); print(" "); for ( uint8_t c = 21; c < 27; c++ ) printHex_op( USBKeys_Keys[ c ], 2 ); print( NL ); } tx_packet->len = 0; // Modifiers *tx_buf++ = 0x01; // ID *tx_buf++ = USBKeys_Modifiers; tx_packet->len += 2; // 4-49 (first 6 bytes) memcpy( tx_buf, USBKeys_Keys, 6 ); tx_buf += 6; tx_packet->len += 6; // 51-155 (Middle 14 bytes) memcpy( tx_buf, USBKeys_Keys + 6, 14 ); tx_buf += 14; tx_packet->len += 14; // 157-164 (Next byte) memcpy( tx_buf, USBKeys_Keys + 20, 1 ); tx_buf += 1; tx_packet->len += 1; // 176-221 (last 6 bytes) memcpy( tx_buf, USBKeys_Keys + 21, 6 ); tx_packet->len += 6; // Send USB Packet usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); USBKeys_Changed = USBKeyChangeState_None; // Mark sent } break; } return; }
void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, UErrorCode *status) { int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case URES_STRING : { int32_t len=0; const UChar*thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ /* if(trunc && len > truncsize) { printIndent(out, indent); u_fprintf(out, "// WARNING: this string, size %d is truncated to %d\n", len, truncsize/2); len = truncsize/2; } */ printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s { \"%S\" } ", key, string); } else { u_fprintf(out, "\"%S\",", string); } if(VERBOSE) { u_fprintf(out, " // STRING"); } u_fprintf(out, "\n"); free(string); } break; case URES_INT : printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":int { %li } ", ures_getInt(resource, status)); if(VERBOSE) { u_fprintf(out, " // INT"); } u_fprintf(out, "\n"); break; case URES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(trunc && len > truncsize) { printIndent(out, indent); u_fprintf(out, "// WARNING: this resource, size %li is truncated to %li\n", len, truncsize/2); len = truncsize/2; } if(U_SUCCESS(*status)) { printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":binary { "); for(i = 0; i<len; i++) { printHex(out, data++); } u_fprintf(out, " }"); if(VERBOSE) { u_fprintf(out, " // BINARY"); } u_fprintf(out, "\n"); } else { reportError(status); } } break; case URES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":intvector { "); for(i = 0; i<len-1; i++) { u_fprintf(out, "%d, ", data[i]); } if(len > 0) { u_fprintf(out, "%d ", data[len-1]); } u_fprintf(out, "}"); if(VERBOSE) { u_fprintf(out, " // INTVECTOR"); } u_fprintf(out, "\n"); } else { reportError(status); } } break; case URES_TABLE : case URES_ARRAY : { UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s ", key); } u_fprintf(out, "{"); if(VERBOSE) { if(ures_getType(resource) == URES_TABLE) { u_fprintf(out, " // TABLE"); } else { u_fprintf(out, " // ARRAY"); } } u_fprintf(out, "\n"); while(ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); printOutBundle(out, t, indent+indentsize, status); } printIndent(out, indent); u_fprintf(out, "}\n"); ures_close(t); } break; default: break; } }
void print(struct node *number, char base){ struct node *curr = number; struct node *prev = NULL; if(iszero(number)) { printf("0"); return; } switch(base){ case 'b': printf("b"); /* Mod each node, starting at the most significant bit, then keep going until you hit the least significant, and return*/ while(curr != NULL){ prev = curr; curr = curr->next; } /* prev is now at the last node */ while (prev != NULL){ printBinary(prev); prev = prev->prev; } break; case 'o': printf("o"); /* Mod each node, starting at the most significant bit, then keep going until you hit the least significant, and return*/ while(curr != NULL){ prev = curr; curr = curr->next; } /* prev is now at the last node */ while (prev != NULL){ printOct(prev); prev = prev->prev; } break; case 'x': printf("x"); /* Mod each node, starting at the most significant bit, then keep going until you hit the least significant, and return*/ while(curr != NULL){ prev = curr; curr = curr->next; } /* prev is now at the last node */ while (prev != NULL){ printHex(prev); prev = prev->prev; } break; case 'd': printf("d"); /* Mod each node, starting at the most significant bit, then keep going until you hit the least significant, and return*/ while(curr != NULL){ prev = curr; curr = curr->next; } /* prev is now at the last node */ while (prev != NULL){ printDecimal(prev); prev = prev->prev; } break; default: printf("Bad Output Base"); } return; }
int readPackets(HSP *sp) { int batch = 0; static uint32_t MySkipCount=1; if(sp->sFlow->sFlowSettings->ulogSubSamplingRate == 0) { // packet sampling was disabled by setting desired rate to 0 return 0; } if(sp->ulog_soc) { for( ; batch < HSP_READPACKET_BATCH; batch++) { char buf[HSP_MAX_MSG_BYTES]; socklen_t peerlen = sizeof(sp->ulog_peer); int len = recvfrom(sp->ulog_soc, buf, HSP_MAX_MSG_BYTES, 0, (struct sockaddr *)&sp->ulog_peer, &peerlen); if(len <= 0) break; if(debug > 1) myLog(LOG_INFO, "got ULOG msg: %u bytes", len); for(struct nlmsghdr *msg = (struct nlmsghdr *)buf; NLMSG_OK(msg, len); msg=NLMSG_NEXT(msg, len)) { if(debug > 1) { myLog(LOG_INFO, "netlink (%u bytes left) msg [len=%u type=%u flags=0x%x seq=%u pid=%u]", len, msg->nlmsg_len, msg->nlmsg_type, msg->nlmsg_flags, msg->nlmsg_seq, msg->nlmsg_pid); } switch(msg->nlmsg_type) { case NLMSG_NOOP: case NLMSG_ERROR: case NLMSG_OVERRUN: // ignore these break; case NLMSG_DONE: // last in multi-part default: { if(--MySkipCount == 0) { /* reached zero. Set the next skip */ MySkipCount = sfl_random((2 * sp->sFlow->sFlowSettings->ulogSubSamplingRate) - 1); /* and take a sample */ // we're seeing type==111 on Fedora14 //if(msg->nlmsg_flags & NLM_F_REQUEST) { } //if(msg->nlmsg_flags & NLM_F_MULTI) { } //if(msg->nlmsg_flags & NLM_F_ACK) { } //if(msg->nlmsg_flags & NLM_F_ECHO) { } ulog_packet_msg_t *pkt = NLMSG_DATA(msg); if(debug > 1) { myLog(LOG_INFO, "mark=%u ts=%s hook=%u in=%s out=%s len=%u prefix=%s maclen=%u\n", pkt->mark, ctime(&pkt->timestamp_sec), pkt->hook, pkt->indev_name, pkt->outdev_name, pkt->data_len, pkt->prefix, pkt->mac_len); if(pkt->mac_len == 14) { u_char macdst[12], macsrc[12]; printHex(pkt->mac+6,6,macsrc,12,NO); printHex(pkt->mac+0,6,macdst,12,NO); uint16_t ethtype = (pkt->mac[12] << 8) + pkt->mac[13]; myLog(LOG_INFO, "%s -> %s (ethertype=0x%04X)", macsrc, macdst, ethtype); } } SFL_FLOW_SAMPLE_TYPE fs = { 0 }; SFLSampler *sampler = NULL; // set the ingress and egress ifIndex numbers. // Can be "INTERNAL" (0x3FFFFFFF) or "UNKNOWN" (0). if(pkt->indev_name[0]) { SFLAdaptor *in = adaptorListGet(sp->adaptorList, pkt->indev_name); if(in && in->ifIndex) { fs.input = in->ifIndex; sampler = getSampler(sp, pkt->indev_name, in->ifIndex); } } else { fs.input = SFL_INTERNAL_INTERFACE; } if(pkt->outdev_name[0]) { SFLAdaptor *out = adaptorListGet(sp->adaptorList, pkt->outdev_name); if(out && out->ifIndex) { fs.output = out->ifIndex; sampler = getSampler(sp, pkt->outdev_name, out->ifIndex); } } else { fs.output = SFL_INTERNAL_INTERFACE; } if(sampler == NULL) { // maybe ULOG sent us a packet on device lo(?) if(debug > 1) myLog(LOG_INFO, "dropped sample with no ifIndex\n"); } else { SFLFlow_sample_element hdrElem = { 0 }; hdrElem.tag = SFLFLOW_HEADER; uint32_t FCS_bytes = 4; uint32_t maxHdrLen = sampler->sFlowFsMaximumHeaderSize; hdrElem.flowType.header.frame_length = pkt->data_len + FCS_bytes; hdrElem.flowType.header.stripped = FCS_bytes; u_char hdr[HSP_MAX_HEADER_BYTES]; if(pkt->mac_len == 14) { // set the header_protocol to ethernet and // reunite the mac header and payload in one buffer hdrElem.flowType.header.header_protocol = SFLHEADER_ETHERNET_ISO8023; memcpy(hdr, pkt->mac, 14); maxHdrLen -= 14; uint32_t payloadBytes = (pkt->data_len < maxHdrLen) ? pkt->data_len : maxHdrLen; memcpy(hdr+14, pkt->payload, payloadBytes); hdrElem.flowType.header.header_length = payloadBytes + 14; hdrElem.flowType.header.header_bytes = hdr; hdrElem.flowType.header.frame_length += 14; } else { // no need to copy - just point at the payload u_char ipversion = pkt->payload[0] >> 4; if(ipversion != 4 && ipversion != 6) { if(debug) myLog(LOG_ERR, "received non-IP packet. Encapsulation is unknown"); } else { hdrElem.flowType.header.header_protocol = (ipversion == 4) ? SFLHEADER_IPv4 : SFLHEADER_IPv6; hdrElem.flowType.header.stripped += 14; // assume ethernet was (or will be) the framing hdrElem.flowType.header.header_length = (pkt->data_len < maxHdrLen) ? pkt->data_len : maxHdrLen; hdrElem.flowType.header.header_bytes = pkt->payload; } } SFLADD_ELEMENT(&fs, &hdrElem); // submit the actual sampling rate so it goes out with the sFlow feed // otherwise the sampler object would fill in his own (sub-sampling) rate. uint32_t actualSamplingRate = sp->sFlow->sFlowSettings->ulogActualSamplingRate; fs.sampling_rate = actualSamplingRate; // estimate the sample pool from the samples. Could maybe do this // above with the (possibly more granular) ulogSamplingRate, but then // we would have to look up the sampler object every time, which // might be too expensive in the case where ulogSamplingRate==1. sampler->samplePool += actualSamplingRate; sfl_sampler_writeFlowSample(sampler, &fs); } } } } } } }
int main( void ) { int i; int j; UINT8 res; UINT8 s; UINT8 NameBuf[20] = {0}; UINT8 CountT = 0; UINT32 U_D; PUINT32 pU_D; pU_D = &U_D; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P1DIR_bit.P1DIR0 = 1; P1OUT_bit.P1OUT0 = 1; UartInit(); code_start: CountT ++; for(i = 0;i<30000;i++); printk("Code Start !\r\n"); printk("程序开始 !\r\n"); do{ for(i = 0;i<30000;i++); res = mInitCH376Host(); }while(res != USB_INT_SUCCESS); printk("USB_INT_SUCCESS !\r\n"); do{ for(i = 0;i<30000;i++); res = CH376DiskConnect( ); /* 查询U盘是否连接,返回USB_INT_SUCCESS则说明当前已连接 */ }while(res!=USB_INT_SUCCESS); printk(" Connect SUCCESS\r\n"); do{ for(i = 0;i<30000;i++); res = CH376DiskMount( ); /* 查询U盘或SD卡是否准备好,有些U盘可能需多次调用才能成功 */ }while(res!=USB_INT_SUCCESS); printk(" U is OK !\r\n"); s = CH376DiskCapacity(pU_D); mStopIfError( s ); printk(" U盘大小:"); printHex((unsigned int)U_D); printHex((unsigned int)(U_D>>16)); printk("\r\n"); s = CH376DiskQuery(pU_D); mStopIfError( s ); printk(" 剩余大小:"); printHex((unsigned int)U_D); printHex((unsigned int)(U_D>>16)); printk("\r\n"); strcpy( NameBuf, "\\2012.TXT" ); /* 目标文件名 */ #if 0 printf( "Open\r\n" ); s = CH376FileOpenPath( NameBuf ); mStopIfError( s ); if ( s == ERR_MISS_FILE ){ printf( "Create\r\n" ); s = CH376FileCreatePath( NameBuf ); /* 新建多级目录下的文件,支持多级目录路径,输入缓冲区必须在RAM中 */ mStopIfError( s ); } printf( "CH376ByteLocate\r\n" ); s = CH376ByteLocate(0xFFFFFFFF); mStopIfError( s ); printf( "Write\r\n" ); strcpy( buf, "时间 数据 ---\xd\n" ); s = CH376ByteWrite( buf, strlen(buf), NULL ); /* 以字节为单位向当前位置写入数据块 */ mStopIfError( s ); strcpy( buf, "2012-12-01 01 ---\xd\n" ); buf[9] = '0' + CountT; for(i = 0; i < 100;i ++){ buf[12] = '0' + i/10; buf[13] = '0' + i%10; printf( "Write %s" ,buf); s = CH376ByteWrite( buf, strlen(buf), NULL ); /* 以字节为单位向当前位置写入数据块 */ mStopIfError( s ); } printf( "Close\r\n" ); s = CH376FileClose( TRUE ); /* 关闭文件,对于字节读写建议自动更新文件长度 */ mStopIfError( s ); #endif /* 如果MY_ADC.TXT文件已经存在则添加数据到尾部,如果不存在则新建文件 */ printf( "Open\n" ); s = CH376FileOpen( NameBuf ); /* 打开文件,该文件在根目录下 */ if ( s == USB_INT_SUCCESS ) { /* 文件存在并且已经被打开,移动文件指针到尾部以便添加数据 */ printf( "File size = %ld\n", CH376GetFileSize( ) ); /* 读取当前文件长度 */ printf( "Locate tail\n" ); s = CH376ByteLocate( 0xFFFFFFFF ); /* 移到文件的尾部 */ mStopIfError( s ); } else if ( s == ERR_MISS_FILE ) { /* 没有找到文件,必须新建文件 */ printf( "Create\n" ); s = CH376FileCreate( NULL ); /* 新建文件并打开,如果文件已经存在则先删除后再新建,不必再提供文件名,刚才已经提供给CH376FileOpen */ mStopIfError( s ); } else mStopIfError( s ); /* 打开文件时出错 */ printf( "Write begin\n" ); s = sprintf( buf, "此前文件长度= %ld 字节\xd\xa", CH376GetFileSize( ) ); /* 注意字符串长度不能溢出buf,否则加大缓冲区或者分多次写入 */ s = CH376ByteWrite( buf, s, NULL ); /* 以字节为单位向文件写入数据 */ mStopIfError( s ); printf( "Write ADC data\n" ); printf( "Current offset ( file point ) is : "); for(i = 0;i<1000;i++){ s = sprintf( buf, "%02d.%02d.%02d.%d\xd\xa", 2012 + i/365, 1 + (i / 30) % 12, 1 + i % 30, i ); /* 将二制制数据格式为一行字符串 */ s = CH376ByteWrite( buf, s, NULL ); /* 以字节为单位向文件写入数据 */ /* 有些U盘可能会要求在写数据后等待一会才能继续操作, 所以,如果在某些U盘中发生数据丢失现象, 建议在每次写入数据后稍作延时再继续 */ for(j = 0;j<30;j++); mStopIfError( s ); printf( "\b\b\b\b\b\b" ); printf( "%6ld", CH376ReadVar32( VAR_CURRENT_OFFSET ) ); /* 读取当前文件指针 */ } printf( "Write end\n" ); strcpy( buf, "今天的ADC数据到此结束\xd\xa" ); s = CH376ByteWrite( buf, strlen( buf ), NULL ); /* 以字节为单位向文件写入数据 */ mStopIfError( s ); /* 如果实际产品中有实时时钟,可以根据需要将文件的日期和时间修改为实际值,参考EXAM10用CH376DirInfoRead/CH376DirInfoSave实现 */ printf( "Close\n" ); s = CH376FileClose( TRUE ); /* 关闭文件,自动计算文件长度,以字节为单位写文件,建议让程序库关闭文件以便自动更新文件长度 */ mStopIfError( s ); do{ for(i = 0;i<30000;i++); P1OUT_bit.P1OUT0 = 1; for(i = 0;i<30000;i++); P1OUT_bit.P1OUT0 = 0; res = CH376DiskConnect( ); /* 查询U盘是否连接,返回USB_INT_SUCCESS则说明当前已连接 */ }while(res!=ERR_DISK_DISCON); printk(" ERR_DISK_DISCON\r\n"); goto code_start; }
static void RFIDCommunication(hid_return ret, HIDInterface** const hid) { int const PATH_IN[] = { PATHIN }; unsigned int SEND_PACKET_LEN1 = 3; unsigned int REPLY_PACKET_LENGTH1 = 3; printf("\n/* * * * * * * * BEGIN COMMUNICATION WITH RFID DEVICE * * * * * * * */"); // SET ANTENNA POWER char PACKET1[] = { 0xC0, 0x03, 0x12 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET1, SEND_PACKET_LEN1); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->First sent: \n"); printHex(PACKET1, SEND_PACKET_LEN1); } char reply1[REPLY_PACKET_LENGTH1+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply1, REPLY_PACKET_LENGTH1, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->First reply:\n"); printHex(reply1, REPLY_PACKET_LENGTH1); } // TAG INVENTORY OPERATION // XXX: returns EPC Data unsigned int SEND_PACKET_LEN2 = 3; unsigned int REPLY_PACKET_LENGTH2 = 64; char PACKET2[] = { 0x31, 0x03, 0x01 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET2, SEND_PACKET_LEN2); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Second sent:\n"); printHex(PACKET2, SEND_PACKET_LEN2); } char reply2[REPLY_PACKET_LENGTH2+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply2, REPLY_PACKET_LENGTH2, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Second reply:\n"); printHex(reply2, REPLY_PACKET_LENGTH2); } // NEXT TAG //unsigned int SEND_PACKET_LEN3 = 3; //unsigned int REPLY_PACKET_LENGTH3 = 64; //char PACKET3[] = { 0x31, 0x03, 0x02 }; //ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET3, SEND_PACKET_LEN3); //if (ret != HID_RET_SUCCESS) { // fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); //} else { // printf("\n\n----->Third sent: \n"); // printHex(PACKET3, SEND_PACKET_LEN3); //} //char reply3[REPLY_PACKET_LENGTH3+1]; //ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply3, REPLY_PACKET_LENGTH3, 100); //if (ret != HID_RET_SUCCESS) { // fprintf(stderr, "interrupt read failed with return code %d\n", ret); //} else { // printf("\n\n----->Third reply: \n", reply3); // printHex(reply3, REPLY_PACKET_LENGTH3); //} // TAG SELECT OPERATION unsigned int SEND_PACKET_LEN4 = 15; unsigned int REPLY_PACKET_LENGTH4 = 3; char PACKET4[] = { 0x33, 0x0F, 0x0C, 0xCF, 0xFA, 0x04, 0x9C, 0x53, 0xE0, 0xC9, 0x7E, 0x13, 0x77, 0xFB, 0x97 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET4, SEND_PACKET_LEN4); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Fourth sent: \n"); printHex(PACKET4, SEND_PACKET_LEN4); } char reply4[REPLY_PACKET_LENGTH4+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply4, REPLY_PACKET_LENGTH4, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Fourth reply: \n", reply4); printHex(reply4, REPLY_PACKET_LENGTH4); } // TAG READ EPC MEMORY OPERATION unsigned int SEND_PACKET_LEN5 = 9; unsigned int REPLY_PACKET_LENGTH5 = 64; char PACKET5[] = { 0x37, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; ret = hid_set_output_report(*hid, PATH_IN, PATHLEN, PACKET5, SEND_PACKET_LEN5); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); } else { printf("\n\n----->Fifth sent: \n"); printHex(PACKET5, SEND_PACKET_LEN5); } char reply5[REPLY_PACKET_LENGTH5+1]; ret = hid_interrupt_read(*hid, EP_INTERRUPT_IN, reply5, REPLY_PACKET_LENGTH5, 100); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "interrupt read failed with return code %d\n", ret); } else { printf("\n\n----->Fifth reply: \n", reply5); printHex(reply5, REPLY_PACKET_LENGTH5); } }
static void printOutBundle(FILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) { static const UChar cr[] = { '\n' }; /* int32_t noOfElements = ures_getSize(resource);*/ int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case RES_STRING : { int32_t len=0; const UChar* thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize/2; } printIndent(out, converter, indent); if(key != NULL) { static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ printCString(out, converter, key, (int32_t)uprv_strlen(key)); printString(out, converter, openStr, (int32_t)(sizeof(openStr)/sizeof(*openStr))); printString(out, converter, string, len); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } else { static const UChar openStr[] = { 0x0022 }; /* "\"" */ static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); printString(out, converter, string, (int32_t)(u_strlen(string))); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } if(verbose) { printCString(out, converter, "// STRING", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); uprv_free(string); } break; case RES_INT : { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); printString(out, converter, num, u_strlen(num)); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INT", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); break; } case RES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize; } if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i<len; i++) { printHex(out, converter, *data++); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, " // BINARY", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting binary value"); } } break; case RES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0076, 0x0065, 0x0063, 0x0074, 0x006F, 0x0072, 0x0020, 0x007B, 0x0020 }; /* ":intvector { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i < len - 1; i++) { int32_t numLen = uprv_itou(num, 20, data[i], 10, 0); num[numLen++] = 0x002C; /* ',' */ num[numLen++] = 0x0020; /* ' ' */ num[numLen] = 0; printString(out, converter, num, u_strlen(num)); } if(len > 0) { uprv_itou(num, 20, data[len - 1], 10, 0); printString(out, converter, num, u_strlen(num)); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INTVECTOR", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting int vector"); } } break; case RES_TABLE : case RES_ARRAY : { static const UChar openStr[] = { 0x007B }; /* "{" */ static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); if(verbose) { if(ures_getType(resource) == RES_TABLE) { printCString(out, converter, "// TABLE", -1); } else { printCString(out, converter, "// ARRAY", -1); } } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); if(suppressAliases == FALSE) { while(U_SUCCESS(*status) && ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); if(U_SUCCESS(*status)) { printOutBundle(out, converter, t, indent+indentsize, pname, status); } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } else { /* we have to use low level access to do this */ Resource r = RES_BOGUS; for(i = 0; i < ures_getSize(resource); i++) { /* need to know if it's an alias */ if(ures_getType(resource) == RES_TABLE) { r = derb_getTableItem(resource->fResData.pRoot, resource->fRes, (int16_t)i); key = derb_getTableKey(resource->fResData.pRoot, resource->fRes, (int16_t)i); } else { r = derb_getArrayItem(resource->fResData.pRoot, resource->fRes, i); } if(U_SUCCESS(*status)) { if(RES_GET_TYPE(r) == RES_ALIAS) { printOutAlias(out, converter, resource, r, key, indent+indentsize, pname, status); } else { t = ures_getByIndex(resource, i, t, status); printOutBundle(out, converter, t, indent+indentsize, pname, status); } } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } printIndent(out, converter, indent); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); ures_close(t); } break; default: break; } }
// Adds a single USB Code to the USB Output buffer // Argument #1: USB Code void Output_usbCodeSend_capability( TriggerMacro *trigger, uint8_t state, uint8_t stateType, uint8_t *args ) { #if enableKeyboard_define == 1 // Display capability name if ( stateType == 0xFF && state == 0xFF ) { print("Output_usbCodeSend(usbCode)"); return; } // Depending on which mode the keyboard is in the USB needs Press/Hold/Release events uint8_t keyPress = 0; // Default to key release // Only send press and release events if ( stateType == 0x00 && state == 0x02 ) // Hold state return; // If press, send bit (NKRO) or byte (6KRO) if ( stateType == 0x00 && state == 0x01 ) // Press state keyPress = 1; // Get the keycode from arguments uint8_t key = args[0]; // Depending on which mode the keyboard is in, USBKeys_Keys array is used differently // Boot mode - Maximum of 6 byte codes // NKRO mode - Each bit of the 26 byte corresponds to a key // Bits 0 - 45 (bytes 0 - 5) correspond to USB Codes 4 - 49 (Main) // Bits 48 - 161 (bytes 6 - 20) correspond to USB Codes 51 - 164 (Secondary) // Bits 168 - 213 (bytes 21 - 26) correspond to USB Codes 176 - 221 (Tertiary) // Bits 214 - 216 unused uint8_t bytePosition = 0; uint8_t byteShift = 0; switch ( USBKeys_Protocol ) { case 0: // Boot Mode // Set the modifier bit if this key is a modifier if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) { if ( keyPress ) { USBKeys_primary.modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0 } else // Release { USBKeys_primary.modifiers &= ~(1 << (key ^ 0xE0)); // Left shift 1 by key XOR 0xE0 } USBKeys_primary.changed |= USBKeyChangeState_Modifiers; } // Normal USB Code else { // Determine if key was set uint8_t keyFound = 0; uint8_t old_sent = USBKeys_Sent; for ( uint8_t curkey = 0, newkey = 0; curkey < old_sent; curkey++, newkey++ ) { // On press, key already present, don't re-add if ( keyPress && USBKeys_primary.keys[newkey] == key ) { keyFound = 1; break; } // On release, remove if found if ( !keyPress && USBKeys_primary.keys[newkey] == key ) { // Shift next key onto this one // (Doesn't matter if it overflows, buffer is large enough, and size is used) USBKeys_primary.keys[newkey--] = USBKeys_primary.keys[++curkey]; USBKeys_Sent--; keyFound = 1; USBKeys_primary.changed = USBKeyChangeState_MainKeys; break; } } // USB Key limit reached if ( USBKeys_Sent >= USB_BOOT_MAX_KEYS ) { warn_print("USB Key limit reached"); break; } // Add key if not already found in the buffer if ( keyPress && !keyFound ) { USBKeys_primary.keys[USBKeys_Sent++] = key; USBKeys_primary.changed = USBKeyChangeState_MainKeys; } } break; case 1: // NKRO Mode // Set the modifier bit if this key is a modifier if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) { if ( keyPress ) { USBKeys_primary.modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0 } else // Release { USBKeys_primary.modifiers &= ~(1 << (key ^ 0xE0)); // Left shift 1 by key XOR 0xE0 } USBKeys_primary.changed |= USBKeyChangeState_Modifiers; break; } // First 6 bytes else if ( key >= 4 && key <= 49 ) { // Lookup (otherwise division or multiple checks are needed to do alignment) // Starting at 0th position, each byte has 8 bits, starting at 4th bit uint8_t keyPos = key + (0 * 8 - 4); // Starting position in array, Ignoring 4 keys switch ( keyPos ) { byteLookup( 0 ); byteLookup( 1 ); byteLookup( 2 ); byteLookup( 3 ); byteLookup( 4 ); byteLookup( 5 ); } USBKeys_primary.changed |= USBKeyChangeState_MainKeys; } // Next 14 bytes else if ( key >= 51 && key <= 155 ) { // Lookup (otherwise division or multiple checks are needed to do alignment) // Starting at 6th byte position, each byte has 8 bits, starting at 51st bit uint8_t keyPos = key + (6 * 8 - 51); // Starting position in array switch ( keyPos ) { byteLookup( 6 ); byteLookup( 7 ); byteLookup( 8 ); byteLookup( 9 ); byteLookup( 10 ); byteLookup( 11 ); byteLookup( 12 ); byteLookup( 13 ); byteLookup( 14 ); byteLookup( 15 ); byteLookup( 16 ); byteLookup( 17 ); byteLookup( 18 ); byteLookup( 19 ); } USBKeys_primary.changed |= USBKeyChangeState_SecondaryKeys; } // Next byte else if ( key >= 157 && key <= 164 ) { // Lookup (otherwise division or multiple checks are needed to do alignment) uint8_t keyPos = key + (20 * 8 - 157); // Starting position in array, Ignoring 6 keys switch ( keyPos ) { byteLookup( 20 ); } USBKeys_primary.changed |= USBKeyChangeState_TertiaryKeys; } // Last 6 bytes else if ( key >= 176 && key <= 221 ) { // Lookup (otherwise division or multiple checks are needed to do alignment) uint8_t keyPos = key + (21 * 8 - 176); // Starting position in array switch ( keyPos ) { byteLookup( 21 ); byteLookup( 22 ); byteLookup( 23 ); byteLookup( 24 ); byteLookup( 25 ); byteLookup( 26 ); } USBKeys_primary.changed |= USBKeyChangeState_QuartiaryKeys; } // Received 0x00 // This is a special USB Code that internally indicates a "break" // It is used to send "nothing" in order to break up sequences of USB Codes else if ( key == 0x00 ) { USBKeys_primary.changed |= USBKeyChangeState_MainKeys; // Also flush out buffers just in case Output_flushBuffers(); break; } // Invalid key else { warn_msg("USB Code not within 4-49 (0x4-0x31), 51-155 (0x33-0x9B), 157-164 (0x9D-0xA4), 176-221 (0xB0-0xDD) or 224-231 (0xE0-0xE7) NKRO Mode: "); printHex( key ); print( NL ); break; } // Set/Unset if ( keyPress ) { USBKeys_primary.keys[bytePosition] |= (1 << byteShift); USBKeys_Sent--; } else // Release { USBKeys_primary.keys[bytePosition] &= ~(1 << byteShift); USBKeys_Sent++; } break; } #endif }