int test05(void) { int n, s, light; char key; Init(); StatusLED(XGN); FrontLED(ON); BackLED(ON, ON); //SerWrite("Begin...", 8); //SerWrite("Waiting for command... ", 23); SerRead(key, 1, 0); if (key == 'g') { SerWrite("Good Morning... Starting...", 27); } else { SerWrite("So... just start... ", 20); } while(1) { for (s=80; s<300; s+=10) { SerWrite("Looping... ", 11); MotorDir(FWD, RWD); MotorSpeed(150,s); SerWrite("Sleep Now! ", 11); for (n=1; n< 100; n++) Sleep(255); if (s > 200) { SerWrite("S>200 ", 6); s=80; } } } return 0; }
bool cSmartCardNagra::SetIFS(unsigned char size) { unsigned char buf[5]; // NAD, PCB, LEN buf[0]=0x21; buf[1]=0xC1; buf[2]=0x01; // Information Field size buf[3]=size; buf[4]=XorSum(buf,4); PRINTF(L_SC_INIT,"Setting IFS to 0x%02X",size); if(SerWrite(buf,5)!=5) { PRINTF(L_SC_ERROR,"failed to write IFS command"); return false; } if(SerRead(buff,5,cardCfg.workTO)!=5 || XorSum(buff,5)) { PRINTF(L_SC_ERROR,"setting IFS to %02x failed",size); return false; } return true; }
bool cSmartCardNagra::DoBlkCmd(unsigned char cmd, int ilen, unsigned char res, int rlen, const unsigned char *data) { /* here we build the command related to the protocol T1 for ROM142 or T14 for ROM181 the only different that i know is the command length byte msg[4], this msg[4]+=1 by a ROM181 smartcard (_nighti_) one example for the cmd$C0 T14 protocol: 01 A0 CA 00 00 03 C0 00 06 91 T1 protocol: 21 00 08 A0 CA 00 00 02 C0 00 06 87 */ unsigned char msg[MAX_LEN+16]; static char nagra_head[] = { 0xA0,0xCA,0x00,0x00 }; memset(msg,0,sizeof(msg)); int c=0; if(!isT14Nagra) { msg[c++]=0x21; msg[c++]=block; block^=0x40; msg[c++]=ilen+6; } else { msg[c++]=0x01; } memcpy(msg+c,nagra_head,sizeof(nagra_head)); c+=sizeof(nagra_head); msg[c]=ilen; msg[c+1]=cmd; int dlen=ilen-2; if(dlen<0) { PRINTF(L_SC_ERROR,"invalid data length encountered"); return false; } msg[c+2]=dlen; if(isT14Nagra) msg[c]++; c+=3; if(data && dlen>0) { memcpy(msg+c,data,dlen); c+=dlen; } msg[c++]=rlen; msg[c]=XorSum(msg,c); c++; if(SerWrite(msg,c)==c) { LDUMP(L_CORE_SC,msg,c,"NAGRA: <-"); cCondWait::SleepMs(10); if(SerRead(buff,3,cardCfg.workTO)!=3) { PRINTF(L_SC_ERROR,"reading back reply failed"); return false; } int xlen=buff[2]+1; if(SerRead(buff+3,xlen,cardCfg.workTO)!=xlen) { PRINTF(L_SC_ERROR,"reading back information block failed"); return false; } xlen+=3; if(XorSum(buff,xlen)) { PRINTF(L_SC_ERROR,"checksum failed"); return false; } LDUMP(L_CORE_SC,buff,xlen,"NAGRA: ->"); if(buff[3]!=res) { PRINTF(L_SC_ERROR,"result not expected (%02X != %02X)",buff[3],res); return false; } if(buff[2]-2!=rlen) { PRINTF(L_SC_ERROR,"result length not expected (%d != %d)",buff[2]-2,rlen); return false; } memcpy(sb,&buff[3+rlen],2); LDUMP(L_CORE_SC,sb,2,"NAGRA: ->"); cCondWait::SleepMs(10); return true; } return false; }