void chksum_gen(int seed, void *buf) { int i; uint64_t chksum; uint8_t *p = buf; chksum = test_checksum((void *)&seed, 4); for (i = 0; i < CHKSUM_NUM; i++) { chksum = test_checksum((void *)&chksum, CHKSUM_LENGTH); memcpy(p, &chksum, CHKSUM_LENGTH); p += CHKSUM_LENGTH; } return; }
int main(int argc, char **argv) { printf("checksum testing started\n"); int result = test_checksum(argc, argv); printf("checksum testing ended\n"); return result; }
/* If packet is from unwanted ip it throws it out and tries again. * Result is placed on pkt[4], pkt_len is set to length of received UDP packet * without the trailing CRC32 * If no packet is available, immediately returns and set pkt_len to 0. */ void get_packet() { int retval; again: pkt_len=0; distant_sai_len=sizeof(distant_sai); retval=recvfrom(fd,(void *)pkt+4,sizeof(pkt)-4,MSG_WAITALL ,(struct sockaddr*)&distant_sai, &distant_sai_len); if (retval>0) { if (distant_port!=distant_sai.sin_port) goto again; pkt_len=retval; if (pkt_len<4) goto again; if (test_checksum()) goto again; pkt_len-=4; return; } if (retval==0) goto again; if (errno==EAGAIN) return; if (errno==EINTR) goto again; fprintf(stderr,"Can't read from UDP socket.\n"); perror(""); die(); }
/* Accepts every IP and port. * Resulting pkt_len is UDP length without 4 (CRC32). * The resulting packet is placed to pkt[4]. * If no packets are available, waits. */ void get_packet_no_test() { int retval; again: pkt_len=0; distant_sai_len=sizeof(distant_sai); wait_for_rw(fd,0); retval=recvfrom(fd,(void *)pkt+4,sizeof(pkt)-4,MSG_WAITALL ,(struct sockaddr*) &distant_sai, &distant_sai_len); if (retval>0) { ip=distant_sai.sin_addr; distant_port=distant_sai.sin_port; pkt_len=retval; if (pkt_len<5) goto again; memcpy(pkt,pkt+5,4); memcpy(opkt,pkt,4); if (test_checksum()) goto again; pkt_len-=4; return; } if (retval==0||errno==EWOULDBLOCK||errno==EINTR) goto again; fprintf(stderr,"Can't read from UDP socket.\n"); perror(""); die(); }
static int test_checksum_all(void) { int is_ok = 0; unsigned long i; struct kbase_device *kbdev = pkbdev; for(i = 0 ; i < ARRAY_SIZE(checksum); i++) is_ok |= (test_checksum( (unsigned int*)phys_to_virt(checksum[i].start), (unsigned int*)phys_to_virt(checksum[i].end), (unsigned long)checksum[i].golden_sum ) << i); if(is_ok != 0) dev_dbg(kbdev->dev, "checksum fail : 0x%x\n", is_ok); return is_ok; }
bool bin_file::load_file(QString path) { QFile f(path); if(f.exists() == false) return false; f.open( QIODevice::ReadOnly ); if(f.isReadable() == false) { // can't open return false; } QByteArray unsplit_bin = f.readAll(); if(f.size() != 0x20000) return false; for(int x=0;x<=0xFFFF;x++) { tside[x] = unsplit_bin.at(x); eside[x] = unsplit_bin.at(x + 0x10000); } if(test_checksum() == false) return false; return true; }
int main(int argc, char *argv[]) { _cleanup_event_unref_ sd_event *e; log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); assert_se(sd_event_new(&e) >= 0); test_request_basic(e); test_checksum(); test_discover_message(e); test_addr_acq(e); return 0; }
unsigned int global_checksum(Float * float_p, int len) { static int initted = 0; unsigned int locsum; #ifdef UNIFORM_SEED_TESTING locsum = test_checksum(float_p,len); #else locsum = local_checksum(float_p, len); #if 1 glb_sum_internal2(&locsum,4,0); // 0 for XOR #else if (!initted) if (sizeof(unsigned int) != sizeof(unsigned long)) ERR.General("","global_checksum", "sizeof(unsigned int)(%d) != sizeof(unsigned long)(%d)\n", sizeof(unsigned int),sizeof(unsigned long)); QMP_xor_ulong ((unsigned long*)&locsum); #endif #endif initted=1; return locsum; }
int main(int argc, char *argv[]) { _cleanup_(sd_event_unrefp) sd_event *e; test_setup_logging(LOG_DEBUG); assert_se(sd_event_new(&e) >= 0); test_request_basic(e); test_request_anonymize(e); test_checksum(); test_discover_message(e); test_addr_acq(e); #if VALGRIND /* Make sure the async_close thread has finished. * valgrind would report some of the phread_* structures * as not cleaned up properly. */ sleep(1); #endif return 0; }
bool bin_file::test_checksum() { if(test_checksum(tside) == false) return false; if(test_checksum(eside) == false) return false; return true; }
//////////////////////////////////////////////////////////////////////////////////////////// // // CAMERA IO FUNCTION // // //////////////////////////////////////////////////////////////////////////////////////////// DWORD CPco_cl_com::Control_Command(void *buf_in,DWORD size_in, void *buf_out,DWORD size_out) { DWORD err=PCO_NOERROR; unsigned char buffer[PCO_SC2_DEF_BLOCK_SIZE]; unsigned int size; WORD com_in,com_out; /* if(hComMutex==NULL) writelog(COMMAND_M,hdriver,"Control_Command: No Mutex no wait"); else { err = WaitForSingleObject(hComMutex,tab_timeout.command*3); writelog(COMMAND_M,hdriver,"Control_Command: Wait Mutex 0x%x done err=%d",hComMutex,err); switch (err) { case WAIT_OBJECT_0: break; // Cannot get mutex ownership due to time-out. case WAIT_TIMEOUT: { writelog(ERROR_M,hdriver,"Control_Command: Timeout waiting for Mutex 0x%x",hComMutex); return PCO_ERROR_TIMEOUT | PCO_ERROR_DRIVER | PCO_ERROR_DRIVER_USB; } // Got ownership of the abandoned mutex object. case WAIT_ABANDONED: { writelog(ERROR_M,hdriver,"Control_Command: Mutex abandoned"); return PCO_ERROR_INVALIDHANDLE | PCO_ERROR_DRIVER | PCO_ERROR_DRIVER_USB; } } } */ // if(clFlushPort) { err=clFlushPort(serialRef); if((int)err<0) { writelog(ERROR_M,hdriver,"Control_Command: pclSerialFlush error = %d",err); } } writelog(COMMAND_M,hdriver,"Control_Command: start= 0x%04x timeout %d",*(unsigned short*)buf_in,tab_timeout.command); com_out=0; com_in=*((WORD*)buf_in); memset(buffer,0,PCO_SC2_DEF_BLOCK_SIZE); size=size_in; err=build_checksum((unsigned char*)buf_in,(int*)&size); err=clSerialWrite(serialRef,(char*)buf_in,&size,tab_timeout.command); if((int)err<0) { writelog(ERROR_M,hdriver,"Control_Command: pclSerialWrite error = %d",err); err=PCO_ERROR_DRIVER_IOFAILURE | PCO_ERROR_DRIVER_CAMERALINK; goto sercom_out; } size=sizeof(WORD)*2; err=clSerialRead(serialRef,(char*)&buffer[0],&size,tab_timeout.command*2); if((int)err<0) { writelog(ERROR_M,hdriver,"Control_Command: pclSerialRead size:4 back %d error = %d",size,err); err=PCO_ERROR_DRIVER_IOFAILURE | PCO_ERROR_DRIVER_CAMERALINK; goto sercom_out; } com_out=*((WORD*)buffer); WORD *b; b=(WORD *)buffer; //size of packet is second WORD b++; size=(int)*b; if(size>PCO_SC2_DEF_BLOCK_SIZE) size=PCO_SC2_DEF_BLOCK_SIZE; size-=sizeof(WORD)*2; writelog(INTERNAL_1_M,hdriver,"Control_Command: before read com_out=0x%04x size %d",com_out,size); if((int)size<0) { writelog(ERROR_M,hdriver,"Control_Command: SerialRead remaining size<0 %d err %d com:0x%04x",size,err,*(WORD *)buffer); err=PCO_ERROR_DRIVER_IOFAILURE | PCO_ERROR_DRIVER_CAMERALINK; goto sercom_out; } if(com_in!=(com_out&0xFF3F)) { writelog(ERROR_M,hdriver,"Control_Command: SerialRead comin 0x%04x != comout&0xFF3F 0x%04x",com_in,com_out&0xFF3F); err=PCO_ERROR_DRIVER_IOFAILURE | PCO_ERROR_DRIVER_CAMERALINK; goto sercom_out; } err=clSerialRead(serialRef,(char*)&buffer[sizeof(WORD)*2],&size,tab_timeout.command*2); if((int)err<0) { writelog(ERROR_M,hdriver,"Control_Command: pclSerialRead size:%d back %d error = %d",*b,size,err); err=PCO_ERROR_DRIVER_IOFAILURE | PCO_ERROR_DRIVER_CAMERALINK; goto sercom_out; } err=PCO_NOERROR; com_out=*((WORD*)buffer); if((com_out&RESPONSE_ERROR_CODE)==RESPONSE_ERROR_CODE) { SC2_Failure_Response resp; memcpy(&resp,buffer,sizeof(SC2_Failure_Response)); err=resp.dwerrmess; if((err&0xC000FFFF)==PCO_ERROR_FIRMWARE_NOT_SUPPORTED) writelog(INTERNAL_1_M,hdriver,"Control_Command: com 0x%x FIRMWARE_NOT_SUPPORTED",com_in); else writelog(ERROR_M,hdriver,"Control_Command: com 0x%x RESPONSE_ERROR_CODE error 0x%x",com_in,err); size= sizeof(SC2_Failure_Response); } else size=size_out; if(err==PCO_NOERROR) { if(com_out!=(com_in|RESPONSE_OK_CODE)) { err=PCO_ERROR_DRIVER_DATAERROR | PCO_ERROR_DRIVER_CAMERALINK; writelog(ERROR_M,hdriver,"Control_Command: Data error com_out 0x%04x should be 0x%04x",com_out,com_in|RESPONSE_OK_CODE); } } writelog(INTERNAL_1_M,hdriver,"Control_Command: before test_checksum read=0x%04x size %d",com_out,size); if(test_checksum(buffer,(int*)&size)==PCO_NOERROR) { size-=1; if(size<size_out) size_out=size; memcpy(buf_out,buffer,size_out); } else err=test_checksum(buffer,(int*)&size); sercom_out: /* if(hComMutex) { if(!ReleaseMutex(hComMutex)) writelog(ERROR_M,hdriver,"Control_Command: release Mutex failed"); writelog(COMMAND_M,hdriver,"Control_Command: Release Mutex 0x%x done",hComMutex); } */ writelog(COMMAND_M,hdriver,"Control_Command: Control_command end 0x%04x err 0x%x",com_out,err); return err ; }