/* * Process a test vector. */ static void ProcessVector(RC2TestVector *vector) { ILRC2Context rc2; unsigned char ciphertext[8]; unsigned char reverse[8]; /* Encrypt and decrypt the plaintext */ ILRC2Init(&rc2, vector->key, vector->keyBits); ILRC2Encrypt(&rc2, vector->plaintext, ciphertext); ILRC2Decrypt(&rc2, ciphertext, reverse); ILRC2Finalize(&rc2); /* Report the results */ printf("Key = "); PrintHex(vector->key, vector->keyBits); printf("Plaintext = "); PrintHex(vector->plaintext, 64); printf("Expected Ciphertext = "); PrintHex(vector->expected, 64); printf("Actual Ciphertext = "); PrintHex(ciphertext, 64); printf("Reverse Plaintext = "); PrintHex(reverse, 64); if(ILMemCmp(vector->expected, ciphertext, 8) != 0) { printf("*** Test failed: ciphertexts do not match ***\n"); } if(ILMemCmp(vector->plaintext, reverse, 8) != 0) { printf("*** Test failed: plaintexts do not match ***\n"); } printf("\n"); }
// Receive test DONE message from target. void CeCosTestSerialFilter::ReceiveDone(CeCosSerial &pSer, unsigned char* data_in, int size) { static const char msg_done[] = "DONE"; unsigned char data_reply[4]; int first = 1; TargetRead(pSer, data_reply, 4); while (0 != strncmp((char*) data_reply, msg_done, 4)) { if (first) { if (data_in && size) { Trace("Data received from target:\n"); PrintHex(data_in, size); Trace("<end>\n"); } Trace("Receiving junk instead of DONE:\n"); first = 0; } PrintHex(data_reply, 4); data_reply[0] = data_reply[1]; data_reply[1] = data_reply[2]; data_reply[2] = data_reply[3]; // The TargetRead call will handle recovery in case of timeout... TargetRead(pSer, &data_reply[3], 1); } }
bool TvDevice::smartcard_transmit(const BYTE *pInput, int inputLen,BYTE *pOutput,int *outputLen) { bool bRet = false; int iRet = 0; #ifdef TVDEVICE_DEBUG_PRINT LOGTRACE(LOGINFO,"===IN=== pInput=%s,len=%d.\n",PrintHex(pInput,inputLen),inputLen); #endif #if defined(WIN32) DWORD dwRetBytes = 0; DWORD dwOutBufSize = *outputLen; BOOL b = DeviceIoControl ( h_, IOCTL_NOVELUSB_GET_SMARTCART_DATA, (LPVOID)pInput, inputLen, pOutput, dwOutBufSize, &dwRetBytes, NULL); if(b) { *outputLen = dwRetBytes; bRet = true; } #else { AutoLockT lock(mutex_); CA_SCARD_CMD ca_cmd; ca_cmd.nCommandLen = inputLen; memcpy(ca_cmd.Command,pInput,inputLen); iRet = ioctl(h_, RT10UP_CA_SC_TRANSMIT, &ca_cmd); if(0 <= iRet) { bRet = true; *outputLen = ca_cmd.nReplyLen; memcpy(pOutput,ca_cmd.Reply,ca_cmd.nReplyLen); } } #endif #ifdef TVDEVICE_DEBUG_PRINT LOGTRACE(LOGINFO,"===OUT===pOutput=%s,len=%d,bRet=%d,iRet=%d.\n",PrintHex(pOutput,*outputLen),*outputLen,bRet,iRet); #endif return bRet; }
bool TvDevice::smartcard_funtion(const BYTE *pInput, int inputLen,BYTE *pOutput,int *outputLen) { bool bRet = false; int iRet = 0; #ifdef TVDEVICE_DEBUG_PRINT LOGTRACE(LOGINFO,"[smartcard_funtion] pInput=%s,inputLen=%d.\n",PrintHex(pInput,inputLen),inputLen); #endif #if defined(WIN32) DWORD dwRetBytes = 0; DWORD dwOutSize = *outputLen; BOOL b = DeviceIoControl ( h_, IOCTL_NOVELUSB_SCFunction(DVBC_TUNER_1), (LPVOID)pInput, inputLen, pOutput, dwOutSize, &dwRetBytes, NULL); if(b) { *outputLen = dwRetBytes; bRet = true; } #else { AutoLockT lock(mutex_); CA_SCARD_CMD ca_cmd; ca_cmd.nCommandLen = inputLen; memcpy(ca_cmd.Command,pInput,inputLen); iRet =ioctl(h_, RT10UP_CA_SC_FUNCTION, &ca_cmd); if(0 <= iRet) { bRet = true; *outputLen = ca_cmd.nReplyLen; memcpy(pOutput,ca_cmd.Reply,ca_cmd.nReplyLen); } } #endif #ifdef TVDEVICE_DEBUG_PRINT LOGTRACE(LOGINFO,"[smartcard_funtion] pOutput=%s,outputLen=%d,iRet=%d.\n",PrintHex(pOutput,*outputLen),*outputLen,iRet); #endif return bRet; }
int TMsg::setAuthInfoKey() { #ifndef MOD_DISABLE_AUTH // key = HMAC-SHA1 (AAA-key, {Key Generation Nonce || client identifier}) char *KeyGenNonce_ClientID; char * AAAkey; uint32_t AAAkeyLen; if (!KeyGenNonce) KeyGenNonceLen = 16; /// @todo set proper size of Client ID (DUID?) (here and in hmac_sha()) KeyGenNonce_ClientID = new char[KeyGenNonceLen+128]; AAAkey = getAAAKey(AAASPI, &AAAkeyLen); std::string fname = getAAAKeyFilename(AAASPI); // error, no file? if (!AAAkey) { Log(Error) << "Auth: Unable to load key file for SPI " << std::hex << AAASPI <<": " << fname << " not found." << std::dec << LogEnd; AuthInfoKey = NULL; delete [] KeyGenNonce_ClientID; return -1; } Log(Debug) << "Auth: AAA-key loaded from file " << fname << "." << LogEnd; PrintHex("Auth: AAA-key: ", AAAkey, AAAkeyLen); memset(KeyGenNonce_ClientID, 0, KeyGenNonceLen+128); if (KeyGenNonce) memcpy(KeyGenNonce_ClientID, KeyGenNonce, KeyGenNonceLen); /// @todo fill also with ClientID (DUID?) PrintHex("Auth: Infokey: using KeyGenNonce+CliendID: ", KeyGenNonce_ClientID, KeyGenNonceLen+128); Log(Debug) << "Auth: AAAKeyLen: " << AAAkeyLen << ", KeyGenNonceLen: " << KeyGenNonceLen << LogEnd; AuthInfoKey = new char[AUTHKEYLEN]; hmac_sha(KeyGenNonce_ClientID, KeyGenNonceLen+128, AAAkey, AAAkeyLen, (char *)AuthInfoKey, 1); PrintHex("Auth: AuthInfoKey (calculated): ", AuthInfoKey, AUTHKEYLEN); delete [] KeyGenNonce_ClientID; #endif return 0; }
void Print (const uint64 &number) { if (number.HighPart == 0) Print (number.LowPart); else PrintHex (number); }
/* Prints reset code and the interrupt type */ static void PrintResetSource(unsigned int Source) { PrintString("ResetSource 0x"); PrintHex(Source); #if 0 PrintString(" - "); switch (Source) { case 0x0000: PrintString("No interrupt pending"); break; case 0x0002: PrintString("Brownout (BOR) (highest priority)"); break; case 0x0004: PrintString("RST/NMI (BOR)"); break; case 0x0006: PrintString("PMMSWBOR (BOR)"); break; case 0x0008: PrintString("Wakeup from LPMx.5 (BOR)"); break; case 0x000A: PrintString("Security violation (BOR)"); break; case 0x000C: PrintString("SVSL (POR)"); break; case 0x000E: PrintString("SVSH (POR)"); break; case 0x0010: PrintString("SVML_OVP (POR)"); break; case 0x0012: PrintString("SVMH_OVP (POR)"); break; case 0x0014: PrintString("PMMSWPOR (POR)"); break; case 0x0016: PrintString("WDT time out (PUC)"); break; case 0x0018: PrintString("WDT password violation (PUC)"); break; case 0x001A: PrintString("Flash password violation (PUC)"); break; case 0x001C: PrintString("PLL unlock (PUC)"); break; case 0x001E: PrintString("PERF peripheral/configuration area fetch (PUC)"); break; case 0x0020: PrintString("PMM password violation (PUC)"); break; default: PrintString("Unknown"); break; } #endif PrintString(CR); }
void FasmCompile() { int len = SendMessage(hWinInput, SCI_GETTEXTLENGTH, NULL, NULL); if (len > 0) { char* buff = new char[len + 1]; SendMessage(hWinInput, SCI_GETTEXT, len + 1, (LPARAM)buff); fasm_Assemble(buff, memBuff, sizeof(memBuff), 100, 0); FASM_STATE* state = reinterpret_cast<FASM_STATE*>(memBuff); std::stringstream ss; if (state->condition == FasmCondition::OK) { PrintHex(state->output_data, state->output_length, ss); } else if (state->condition == FasmCondition::FERROR) { ss << "Error: " << FasmErrorToString(state->error_code) << " at line " << state->error_data->line_number; } else { ss << "Error: " << FasmConditionToString(state->condition); } std::string output = ss.str(); SendMessage(hWinOutput, SCI_SETTEXT, output.length(), (LPARAM)output.c_str()); delete buff; } }
static bool PrintResEvent(void) { SmonViceId Vice; unsigned long Time; unsigned long Volid; long HighWaterMark; long AllocNumber; long DeallocNumber; unsigned long ResOpSize; ResOpEntry *ResOp; int sum = ReadResEvent(&Vice,&Time,&Volid,&HighWaterMark,&AllocNumber, &DeallocNumber,&ResOpSize,&ResOp); if (sum != 0) LogMsg(0,LogLevel,LogFile,"**** BAD RESOLUTION RECORD ****"); printf("%-12s: ","SRVRES"); PrintViceId(&Vice); PrintDecimal(Time); PrintHex(Volid); PrintDecimal(HighWaterMark); PrintDecimal(AllocNumber); PrintDecimal(DeallocNumber); printf("\n"); PrintResOpArray(ResOpSize,ResOp); printf("\n"); printf("=================================================\n"); delete [] ResOp; if (sum) return mtrue; else return mfalse; }
// ----------------------------------------------------------------------------- // COMASuplWapListener::CheckBinaryContentType // // ----------------------------------------------------------------------------- // TBool COMASuplWapListener::CheckBinaryContentType(CPushMessage* aPushMsg) { TPtrC8 field; TBool isHeaderPresent = aPushMsg->GetBinaryHeaderField(EHttpContentType, field); #ifdef _DEBUG //Log the received message iTrace->Trace( _L( "Received Binary Content Type is:" ), KTraceFileName, __LINE__ ); PrintHex(field, __LINE__); #endif if( isHeaderPresent ) { iTrace->Trace( _L( "Binary Content type present..." ), KTraceFileName, __LINE__ ); TUint8 code = field[0]; //if(code>0x7F && ((code&0x7F) == KSupportedHEXContentType) ) // Content-type-value = Short-integer if (field[1] == 0x03 && field[2] == 0x12) { return ETrue; } } else { iTrace->Trace( _L( "No Binary Content type present..." ), KTraceFileName, __LINE__ ); } return EFalse; }
boolean Adafruit_NFCShield_I2C::writeGPIO(uint8_t pinstate) { uint8_t errorbit; // Make sure pinstate does not try to toggle P32 or P34 pinstate |= (1 << PN532_GPIO_P32) | (1 << PN532_GPIO_P34); // Fill command buffer pn532_packetbuffer[0] = PN532_COMMAND_WRITEGPIO; pn532_packetbuffer[1] = PN532_GPIO_VALIDATIONBIT | pinstate; // P3 Pins pn532_packetbuffer[2] = 0x00; // P7 GPIO Pins (not used ... taken by I2C) #ifdef PN532DEBUG Serial.print("Writing P3 GPIO: "); Serial.println(pn532_packetbuffer[1], HEX); #endif // Send the WRITEGPIO command (0x0E) if (! sendCommandCheckAck(pn532_packetbuffer, 3)) return 0x0; // Read response packet (00 00 FF PLEN PLENCHECKSUM D5 CMD+1(0x0F) DATACHECKSUM) wirereaddata(pn532_packetbuffer, 8); #ifdef PN532DEBUG Serial.print("Received: "); PrintHex(pn532_packetbuffer, 8); Serial.println(""); #endif return (pn532_packetbuffer[6] == 0x0F); }
static bool PrintVCB() { VmonVenusId Venus; long VenusInit; long Time; VolumeId Volume; VCBStatistics Stats; int sum = ReadVCB(&Venus, &VenusInit, &Time, &Volume, &Stats); if (sum != 0) LogMsg(0,LogLevel,LogFile,"**** BAD VCB RECORD ****"); printf("%-12s: ","VCB"); PrintVenusId(&Venus); PrintDecimal(VenusInit); PrintDecimal(Time); printf("\n"); PrintHex(Volume); printf("\n"); PrintVCBStats(&Stats); printf("\n"); printf("=================================================\n"); if (sum) return mtrue; else return mfalse; }
/******************************************************************** 函数功能:读取端点缓冲区函数。 入口参数:Endp:端点号;Len:需要读取的长度;Buf:保存数据的缓冲区。 返 回:实际读到的数据长度。 备 注:无。 ********************************************************************/ uint8 UsbChipReadEndpointBuffer(uint8 Endp, uint8 Len, uint8 *Buf) { uint8 i,j; UENUM=Endp; //选择端点 j=UEBCLX; //获取数据长度 if(j>Len) //如果要读的字节数比实际接收到的数据长 { j=Len; //则只读指定的长度数据 } #ifdef DEBUG1 //如果定义了DEBUG1,则需要显示调试信息 Prints("读端点"); PrintLongInt(Endp); Prints("缓冲区"); PrintLongInt(j); //实际读取的字节数 Prints("字节。\r\n"); #endif for(i=0;i<j;i++) { *(Buf+i)=UEDATX; //从FIFO中读一字节数据 #ifdef DEBUG1 PrintHex(*(Buf+i)); //如果需要显示调试信息,则显示读到的数据 if(((i+1)%16)==0)Prints("\r\n"); //每16字节换行一次 #endif } #ifdef DEBUG1 if((j%16)!=0)Prints("\r\n"); //换行。 #endif return j; //返回实际读取的字节数。 }
/******************************************************************** 函数功能:将数据写入端点缓冲区函数。 入口参数:Endp:端点号;Len:需要发送的长度;Buf:保存数据的缓冲区。 返 回:Len的值。 备 注:无。 ********************************************************************/ uint8 UsbChipWriteEndpointBuffer(uint8 Endp,uint8 Len,uint8 * Buf) { uint8 i; #ifdef DEBUG1 //如果定义了DEBUG1,则需要显示调试信息 Prints("写端点"); PrintLongInt(Endp); Prints("缓冲区"); PrintLongInt(Len); //写入的字节数 Prints("字节。\r\n"); #endif for(i=0;i<Len;i++) { AT91C_UDP_FDR[Endp]=*(Buf+i); //将数据写到FIFO中 #ifdef DEBUG1 PrintHex(*(Buf+i)); //如果需要显示调试信息,则显示发送的数据 if(((i+1)%16)==0)Prints("\r\n"); //每16字节换行一次 #endif } #ifdef DEBUG1 if((Len%16)!=0)Prints("\r\n"); //换行 #endif UsbChipValidateBuffer(Endp); //使端点数据有效 return Len; //返回Len }
void PrintVal (const char *message, const uint64 &value, bool newLine, bool hex) { Print (message); Print (": "); PrintHex (value); if (newLine) PrintEndl(); }
int main() { HMODULE hNsi = LoadLibraryW(L"Nsi.dll"); NsiGetParameterProc _NsiGetParameter = (NsiGetParameterProc)GetProcAddress(hNsi, "NsiGetParameter"); // Declare and initialize variables PIP_INTERFACE_INFO pInfo = NULL; ULONG ulOutBufLen = 0; DWORD dwRetVal = 0; int iReturn = 1; int i; // Make an initial call to GetInterfaceInfo to get // the necessary size in the ulOutBufLen variable dwRetVal = GetInterfaceInfo(NULL, &ulOutBufLen); if (dwRetVal == ERROR_INSUFFICIENT_BUFFER) { pInfo = (IP_INTERFACE_INFO *)MALLOC(ulOutBufLen); if (pInfo == NULL) { printf ("Unable to allocate memory needed to call GetInterfaceInfo\n"); return 1; } } // Make a second call to GetInterfaceInfo to get // the actual data we need dwRetVal = GetInterfaceInfo(pInfo, &ulOutBufLen); if (dwRetVal == NO_ERROR) { printf("Number of Adapters: %ld\n\n", pInfo->NumAdapters); for (i = 0; i < pInfo->NumAdapters; i++) { printf("Adapter Index[%d]: %ld\n", i, pInfo->Adapter[i].Index); NET_LUID Luid; NETIO_STATUS st = ConvertInterfaceIndexToLuid(pInfo->Adapter[i].Index, &Luid); if (st == NO_ERROR) { BYTE OutputBuffer[0xB8] = { /* zero padding */ }; DWORD nsi_st = _NsiGetParameter(1, NPI_MS_IPV4_MODULEID, 7, &Luid, sizeof(Luid), 0, OutputBuffer, sizeof(OutputBuffer), 0); if (nsi_st == NO_ERROR) { PrintHex(OutputBuffer, sizeof(OutputBuffer)); } } } iReturn = 0; } else if (dwRetVal == ERROR_NO_DATA) { printf ("There are no network adapters with IPv4 enabled on the local system\n"); iReturn = 0; } else { printf("GetInterfaceInfo failed with error: %d\n", dwRetVal); iReturn = 1; } FREE(pInfo); return (iReturn); }
void list_print(virus *virus_list){ while(virus_list != 0){ printf("Virus name: %s\n",virus_list->name); printf("Virus size: %d\n",virus_list->length); printf("signature:\n"); PrintHex(virus_list->signature, virus_list->length); virus_list = virus_list->next; } }
void TMsg::setAuthInfoKey(char* ptr) { AuthInfoKey = ptr; if (!ptr) { Log(Debug) << "Strange, NULL pointer to setAuthInfoKey()" << LogEnd; return; } PrintHex("Auth: setting auth info to: ", AuthInfoKey, AUTHKEYLEN); }
bool CeCosTestMonitorFilter::FilterFunctionProper(void*& pBuf, unsigned int& nRead) { char* buffer = (char*) pBuf; if (m_bOptVerbose) PrintHex((unsigned char*) buffer, nRead, m_eOrigin); return true; }
status_t MSNConnection::HandleMSG( Command * command ) { LOG(kProtocolName, liDebug, "C %lX: Processing MSG", this); HTTPFormatter http(command->Payload(0), strlen(command->Payload(0))); BString type; status_t result = http.HeaderContents("Content-Type", type); if (result == B_OK) { // Handle type if (type == "text/plain; charset=UTF-8") { LOG(kProtocolName, liHigh, "C %lX: Got a private message [%s] from <%s>", this, http.Content(), command->Param(0)); fManager->fHandler->MessageFromUser(command->Param(0), http.Content()); } else if (type == "text/x-msmsgscontrol") { LOG(kProtocolName, liHigh, "C %lX: User typing from <%s>", this, command->Param(0)); fManager->fHandler->UserIsTyping(http.HeaderContents("TypingUser"), tnStartedTyping); } else if (type == "text/x-msmsgsinitialemailnotification; charset=UTF-8") { LOG(kProtocolName, liHigh, "C %lX: HotMail number of messages in Inbox", this ); // Ignore this. It just tells us how many emails are in the Hotmail inbox. } else if (type == "text/x-msmsgsprofile; charset=UTF-8") { LOG(kProtocolName, liHigh, "C %lX: Profile message", this ); // Maybe we should process this, it's a profile message. } else if (type == "text/x-msmsgsinvite; charset=UTF-8") { LOG(kProtocolName, liDebug, "C %lX: Got an invite, we're popular!", this); PrintHex((uchar *)command->Payload(0), strlen(command->Payload(0))); } else if (type == "application/x-msnmsgrp2p") { LOG(kProtocolName, liDebug, "C %lX: Got Peer To Peer message!", this); } else { LOG(kProtocolName, liDebug, "C %lX: Got message of unknown type <%s>", this, type.String()); PrintHex((uchar *)command->Payload(0), strlen(command->Payload(0))); } } else { LOG(kProtocolName, liDebug, "C %lX: No Content-Type in message!", this); } return B_OK; }
static bool PrintVmonSession() { int sum; VmonVenusId Venus; VmonSessionId Session; VolumeId Volume; UserId User; VmonAVSG AVSG; unsigned long StartTime; unsigned long EndTime; unsigned long CETime; VmonSessionEventArray Events; SessionStatistics Stats; CacheStatistics CacheStats; sum = ReadSessionRecord(&Venus, &Session, &Volume, &User, &AVSG, &StartTime, &EndTime, &CETime, &Events, &Stats, &CacheStats); if (sum != 0) LogMsg(0,LogLevel,LogFile,"**** BAD SESSION RECORD ****"); printf("%-12s: ", "SESSION"); PrintVenusId(&Venus); PrintHex(Session); PrintHex(Volume); PrintDecimal(User); PrintDecimal(StartTime); PrintDecimal(EndTime); PrintDecimal(CETime); printf("\n"); PrintAVSG(&AVSG); printf("\n"); PrintEventArray(&Events); printf("\n"); PrintSessionStats(&Stats); printf("\n-----------\n"); PrintCacheStats(&CacheStats); printf("=================================================\n"); if (sum) return mtrue; else return mfalse; }
void CAStreamBasicDescription::PrintToLog(const AudioStreamBasicDescription& inDesc) { PrintFloat (" Sample Rate: ", inDesc.mSampleRate); Print4CharCode (" Format ID: ", inDesc.mFormatID); PrintHex (" Format Flags: ", inDesc.mFormatFlags); PrintInt (" Bytes per Packet: ", inDesc.mBytesPerPacket); PrintInt (" Frames per Packet: ", inDesc.mFramesPerPacket); PrintInt (" Bytes per Frame: ", inDesc.mBytesPerFrame); PrintInt (" Channels per Frame: ", inDesc.mChannelsPerFrame); PrintInt (" Bits per Channel: ", inDesc.mBitsPerChannel); }
int main(int argc, char* argv[]) { HCRYPTPROV hProv; HCRYPTKEY hKey; if (argc != 2) { fprintf(stderr, "Usage: CryptTest <data>\n"); exit(1); } char* plaintext = argv[1]; if (!CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { PrintError("CryptAcquireContext"); } while (1) { puts("Generating key..."); if (!CryptGenKey(hProv, CALG_RC2, 0x800000, &hKey)) { PrintError("CryptGenKey"); } puts("New key generated..."); DWORD plaintextSize = strlen(plaintext); DWORD cipherSize = plaintextSize; if (!CryptEncrypt(hKey, 0, 1, 0, 0, &cipherSize, 0)) { PrintError("CryptEncrypt[0]"); } BYTE* data = (BYTE*)malloc(cipherSize); strncpy_s(data, cipherSize, plaintext, plaintextSize); if (!CryptEncrypt(hKey, 0, 1, 0, data, &plaintextSize, cipherSize)) { PrintError("CryptEncrypt[0]"); } puts("Encrypted data:"); PrintHex(data, cipherSize); puts("\n\n"); if (!CryptDestroyKey(hKey)) { PrintError("CryptDestroyKey"); } Sleep(5000); } if (!CryptReleaseContext(hProv, 0)) { PrintError("CryptReleaseContext"); } getchar(); return 0; }
void Print(Reader r, int depth) { while(r.Next()) { std::cout << std::setw(depth * 2) << ' ' << StaticName::ToString(r.Type()) << std::endl; Print(r.Follow(), depth + 1); } std::cout << std::setw(depth * 2) << ' ' << r.BytesLeft() << ": "; PrintHex(r.Data(), r.BytesLeft()); std::cout << std::endl; }
int ddrtest(void) { volatile unsigned int * src= (volatile unsigned int *) 0x41f00000; volatile unsigned int * dst= (volatile unsigned int *) 0x40000000; unsigned int temp; unsigned int i; for(i=0 ; i < 0xffffff; i++ ) { // if (i & 0xf) // continue; // dst[i] = ~0; // else // dst[i] = 0; dst[i]= 0xffffff - i; } //verify for(i=0 ; i < 0xffffff; i++ ) { // if (i & 0xf) // continue; if((temp = dst[i]) != 0xffffff - i) { puts("addr:"); PrintHex(i); puts("should:"); PrintHex(0xffffff - i); puts("bad:"); // PrintHex(src[i]); // puts("should:"); PrintHex(temp); // puts("\r\n"); } // printf("bad add:%x, val:%x, shouldbe %x\n", &dst[i], temp, src[i%(64*1024)]); } return 0; }
/* Make up an ethernet header if the packet doesn't have one. * * A firmware bug common among several devices cause them to send raw * IP packets under some circumstances. There is no way for the * driver/host to know when this will happen. And even when the bug * hits, some packets will still arrive with an intact header. * * The supported devices are only capably of sending IPv4, IPv6 and * ARP packets on a point-to-point link. Any packet with an ethernet * header will have either our address or a broadcast/multicast * address as destination. ARP packets will always have a header. * * This means that this function will reliably add the appropriate * header iff necessary, provided our hardware address does not start * with 4 or 6. * * Another common firmware bug results in all packets being addressed * to 00:a0:c6:00:00:00 despite the host address being different. * This function will also fixup such packets. */ static int GobiNetDriverLteRxFixup(struct usbnet *dev, struct sk_buff *skb) { __be16 proto; DBG( "From Modem: "); PrintHex (skb->data, skb->len); /* usbnet rx_complete guarantees that skb->len is at least * hard_header_len, so we can inspect the dest address without * checking skb->len */ switch (skb->data[0] & 0xf0) { case 0x40: proto = htons(ETH_P_IP); break; case 0x60: proto = htons(ETH_P_IPV6); break; case 0x00: if (is_multicast_ether_addr(skb->data)) return 1; /* possibly bogus destination - rewrite just in case */ skb_reset_mac_header(skb); goto fix_dest; default: /* pass along other packets without modifications */ return 1; } if (skb_headroom(skb) < ETH_HLEN) return 0; skb_push(skb, ETH_HLEN); skb_reset_mac_header(skb); eth_hdr(skb)->h_proto = proto; memset(eth_hdr(skb)->h_source, 0, ETH_ALEN); fix_dest: memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN); DBG( "To IP Stack: "); PrintHex (skb->data, skb->len); return 1; }
unsigned char *ToshibaGetResponse( int *length ) { if( strlen(toshiba_state.response) > 0 ) { /* Add a 0x0d to the end and return */ toshiba_state.response[strlen(toshiba_state.response)] = 0x0d; *length = strlen(toshiba_state.response); if( PACKET_DEBUG ) { PrintHex( "= Outgoing: ", (const unsigned char *)toshiba_state.response, strlen(toshiba_state.response) ); } return (unsigned char *)toshiba_state.response; } /* Nothing to respond with */ *length = 0; return NULL; }
void PrintHexDump (byte *mem, size_t size, uint16 *memSegment) { const size_t width = 16; for (size_t pos = 0; pos < size; ) { for (int pass = 1; pass <= 2; ++pass) { size_t i; for (i = 0; i < width && pos < size; ++i) { byte dataByte; if (memSegment) { __asm { push es mov si, ss:memSegment mov es, ss:[si] mov si, ss:mem add si, pos mov al, es:[si] mov dataByte, al pop es } pos++; } else dataByte = mem[pos++]; if (pass == 1) { PrintHex (dataByte); PrintChar (' '); } else PrintChar (IsPrintable (dataByte) ? dataByte : '.'); } if (pass == 1) { pos -= i; PrintChar (' '); } } PrintEndl (); }
//------------------------------------------------------------------------------ void SendData(unsigned char *data,int length) { dword bytes_written; bytes_written=0; if(handle) { if((bytes_written=write(handle, data, length)) != length) printf("SendData(): system call \"write()\" return error.\n Asked for %d bytes to be written, but %d bytes reported as written.\n", length,(int)bytes_written); else PrintHex("Sent: ", data, length); } else printf("SendData(): \"handle\" is null\n"); }
uint8_t Adafruit_NFCShield_I2C::readGPIO(void) { pn532_packetbuffer[0] = PN532_COMMAND_READGPIO; // Send the READGPIO command (0x0C) if (! sendCommandCheckAck(pn532_packetbuffer, 1)) return 0x0; // Read response packet (00 00 FF PLEN PLENCHECKSUM D5 CMD+1(0x0D) P3 P7 IO1 DATACHECKSUM) wirereaddata(pn532_packetbuffer, 11); /* READGPIO response should be in the following format: byte Description ------------- ------------------------------------------ b0..6 Frame header and preamble b7 P3 GPIO Pins b8 P7 GPIO Pins (not used ... taken by I2C) b9 Interface Mode Pins (not used ... bus select pins) b10 checksum */ #ifdef PN532DEBUG Serial.print("Received: "); PrintHex(pn532_packetbuffer, 11); Serial.println(""); Serial.print("P3 GPIO: 0x"); Serial.println(pn532_packetbuffer[7], HEX); Serial.print("P7 GPIO: 0x"); Serial.println(pn532_packetbuffer[8], HEX); Serial.print("IO GPIO: 0x"); Serial.println(pn532_packetbuffer[9], HEX); // Note: You can use the IO GPIO value to detect the serial bus being used switch(pn532_packetbuffer[9]) { case 0x00: // Using UART Serial.println("Using UART (IO = 0x00)"); break; case 0x01: // Using I2C Serial.println("Using I2C (IO = 0x01)"); break; case 0x02: // Using I2C Serial.println("Using I2C (IO = 0x02)"); break; } #endif return pn532_packetbuffer[6]; }