void * AP_CCCI_RX (void* lpParameter) { char buf_ack [BUF_SIZE] = {0}; char buf_log [BUF_SIZE] = {0}; int rd_len, wr_len; LOGD(TAG "Enter AP_CCCI_RX()\n"); for (;;) { #ifdef MTK_DT_SUPPORT if(g_mdFlag==1) rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); if(g_mdFlag==2) rd_len = read_ack (g_fd_atcmdmd2, buf_ack, BUF_SIZE); #else rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); #endif if (rd_len>0) { memcpy (buf_log, buf_ack, rd_len); buf_log[rd_len] = '\0'; LOGD(TAG "AP_CCCI_RX: %s, rd_len = %d\n", buf_log, rd_len); ACK_Pre_Process(buf_log); wr_len = write_chars (g_fd_uart, buf_ack, rd_len); if (wr_len != rd_len) LOGE(TAG "AP_CCCI_RX: wr_len != rd_len\n"); } } //pthread_exit(NULL); }
int main(int argc, char **argv) { gss_ctx_id_t acceptor; int dummy; /* Make the PRNG work since we're not using krb5_init_context. */ krb5_c_random_os_entropy(NULL, 0, &dummy); read_lucid_context(&acceptor); send_ack(STDOUT_FILENO); read_wrap_token(acceptor); send_ack(STDOUT_FILENO); read_mic_token(acceptor); send_ack(STDOUT_FILENO); read_iov_token(acceptor); send_ack(STDOUT_FILENO); send_wrap_token(acceptor); read_ack(STDIN_FILENO); send_mic_token(acceptor); read_ack(STDIN_FILENO); send_iov_token(acceptor); read_ack(STDIN_FILENO); cleanup_context(acceptor); return 0; }
/// write to a connect I2C slave device // /// This function writes n bytes of data to the device with address a /// that is connected to the I2C bus. void write( fast_byte a, const byte data[], fast_byte n ) override { write_start(); write_byte( a << 1 ); for( fast_byte i = 0; i < n; i++ ){ read_ack(); write_byte( data[ i ] ); } read_ack(); write_stop(); }
/*--------------------------------------------------------------------------- TITLE : read_reg_to_buf WORK : ARG : void RET : void ---------------------------------------------------------------------------*/ void cI2C::read_reg_to_buf(uint8_t add, uint8_t reg, uint8_t *buf, uint8_t size) { rep_start(add<<1); // I2C write direction write(reg); // register selection rep_start((add<<1) | 1); // I2C read direction uint8_t *b = buf; while (--size) *b++ = read_ack(); // acknowledge all but the final byte *b = read_nak(); }
/// read from a connected I2C slave device // /// This function reads n bytes of data from the device with address a /// that is connected to the I2C bus. void read( fast_byte a, byte data[], fast_byte n ) override { write_start(); write_byte( ( a << 1 ) | 0x01 ); read_ack(); for( fast_byte i = 0; i < n; i++ ){ if( i > 0 ){ write_ack(); } data[ i ] = read_byte(); } write_stop(); }
u8 NFC_Module::write_cmd_check_ack(u8 *cmd, u8 len) { write_cmd(cmd, len); wait_ready(); #ifdef PN532DEBUG Serial.println("IRQ received"); #endif // read acknowledgement if (!read_ack()) { #ifdef PN532DEBUG Serial.println("No ACK frame received!"); #endif return false; } return true; // ack'd command }
int login_server(int id,char *hlrcode,char *hlrport, char *mgr_user, char *mgr_pswd, char *mgr_term) { int readlen,msglen,retn; loginreqptr=(struct login_req *)tcpbuf.data; strcpy(loginreqptr->username, mgr_user); strcpy(loginreqptr->userpswd, mgr_pswd); strcpy(loginreqptr->hlrcode, hlrcode); loginreqptr->hlrport = hlrport[0]; loginreqptr->termtype = mgr_term[0]; memcpy(loginreqptr->reserve, " ", 2); if(send_req(id,DECRYPT,TX_END,SRV_LOGIN,1,LOGINREQLEN)<0) { fprintf(logfp,"send_req(%d) failed[%d]\n",id,errno); return -2; } readlen = read_ack(connid, &tcpbuf); if(readlen != 0) { fprintf(logfp,"readnet(%d,8,%d)=%d failed!\n",id,msglen-8,readlen); return -6; } printf("RCV:%s~\n",(char *)&tcpbuf); loginackptr=(struct login_ack *)tcpbuf.data; retn=get_length(loginackptr->retn,4); encrypt_char=loginackptr->encrypt; memset(cipher,0x0,sizeof(cipher)); strncpy(cipher,loginackptr->cipher,8); printf("cipher===%s~\n",cipher); return retn; }
void read_ctl(struct params *p, struct ieee80211_frame *wh, int len) { switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) { case IEEE80211_FC0_SUBTYPE_RTS: read_rts(p, wh, len); break; case IEEE80211_FC0_SUBTYPE_ACK: read_ack(p, wh, len); break; case IEEE80211_FC0_SUBTYPE_CTS: break; default: printf("wtf %d\n", (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) >> IEEE80211_FC0_SUBTYPE_SHIFT); abort(); break; } #if 0 printf("ctl\n"); #endif }
int main(int argc,char **argv,char **envp) { long command_id; char hlr_code[8]; char phone_no[20]; char command_code[8]; char op_code[8]; char imsi_no[32]; char new_phone[20]; char new_imsi[32]; char business_status[8]; char mgr_user[20], mgr_pswd[20], mgr_term[10]; int ret; char inputstr[2048],ss[64]; int i,status,today; char srvip[32]; int srvport; char logfilename[256],logdir[256]; time_t t; struct tm *tv; char chhlr; int msglen,readlen,headlen,tcplen,bodylen; int transid; char order_fname[256],reply_fname[256],query_fname[256],cfginfo[1024],*p,*d; int line; FILE *cfgfp; char cfgstr[256]; procname=argv[0]; logfp=NULL; memset(inputstr,0x0,sizeof(inputstr)); for(i=0;i<argc;i++) { strcat(inputstr,argv[i]); strcat(inputstr," "); } if(GenDaemon()<0) { printf("GenDaemon() failed!\n"); exit(1); } signal(SIGTERM,LogOut); signal(SIGPIPE,SIG_IGN); signal(SIGCLD,SIG_IGN); signal(SIGINT,SIG_IGN); memset(hlrcode,0x0,sizeof(hlrcode)); memset(hlrport,0x0,sizeof(hlrport)); memset(logdir,0x0,sizeof(logdir)); while(--argc>0) { if(argv[argc][0]!='-') usage("Incorrect Parameter!"); printf("CMD:%c\n",argv[argc][1]); switch(argv[argc][1]) { case 'H': strncpy(hlrcode,argv[argc]+2,4); break; case 'N': strncpy(hlrport,argv[argc]+2,4); break; case 'L': strncpy(logdir,argv[argc]+2,240); break; case 'V': printf("\n\n version = %s\n\n",VERSION); exit(0); case 't': case 'T': test_flag = 1; break; default: usage("Unknow Parameter!"); break; } } printf("hlrcode===%s[%s]~\n",hlrcode,hlrport); if(strlen(hlrcode)!=3) usage("Incorrect parameter [hlrcode]!\n"); if(strlen(hlrport)!=1) usage("Incorrect parameter [hlrport]!\n"); if(strlen(logdir)<1) strcpy(logdir,getenv("LOGDIR")); if(testdir(logdir)) usage("Incorrect parameter [logdir]!"); time(&t); tv=localtime(&t); memset(logfilename,0x0,sizeof(logfilename)); sprintf(logfilename,"%s/erc%04d%02d%02d.%s.%s",logdir, tv->tm_year+1900,tv->tm_mon+1,tv->tm_mday,hlrcode,hlrport); logfp=fopen(logfilename,"a"); if(logfp==NULL) { printf("can't open %s for LOG!\n",logfilename); exit(1); } fprintf(logfp,"INIT %04d/%02d/%02d %02d:%02d:%02d\n", tv->tm_year+1900,tv->tm_mon+1,tv->tm_mday, tv->tm_hour,tv->tm_min,tv->tm_sec); fprintf(logfp,"%s[%d]\n",inputstr,argc); fflush(logfp); today=tv->tm_mday; /************ 获取连接配置信息 ********************/ if(get_hlr_cfg(hlrcode, atoi(hlrport), gsmip, &gsmport, gsmuser, gsmpswd, order_fname,reply_fname,query_fname, srvip, &commport, NULL, mgr_user, mgr_pswd, mgr_term) != 0) { fprintf(logfp,"get_cfg_filename(%s) failed!\n",hlrcode); fclose(logfp); exit(1); } /************ GET ORDER INFO ***********************/ cfgfp=fopen(order_fname,"r"); if(cfgfp==NULL) { fprintf(logfp,"Can't open %s for read[%d]\n",order_fname,errno); fclose(logfp); exit(1); } line=0; memset(cfginfo,0x0,sizeof(cfginfo)); while(fgets(cfginfo,sizeof(cfginfo),cfgfp)) { line++; if(cfginfo[0]=='#' || cfginfo[0]=='\r' || cfginfo[0]=='\n') { memset(cfginfo,0x0,sizeof(cfginfo)); continue; } if(strncmp(cfginfo,"OP",2) || (p=strchr(cfginfo,':'))==NULL) { fprintf(logfp,"Incorrect cfg_info[line=%d]\n",line); fclose(cfgfp); fclose(logfp); exit(1); } orderptr=(struct order_info *)malloc(sizeof(struct order_info)); memset(orderptr,0x0,sizeof(struct order_info)); orderptr->ordercode=atoi(cfginfo+2); strcpy(orderptr->orderinfo,rlspace(p+1)); if(strlen(orderptr->orderinfo)==0 || strlen(orderptr->orderinfo)>1000) { fprintf(logfp,"Incorrect cfg_info[line=%d]\n",line); fclose(cfgfp); fclose(logfp); exit(1); } ordertail=&orderhead; while(ordertail->next) { if(ordertail->next->ordercode==orderptr->ordercode) { fprintf(logfp,"ORDER_CODE[%d] is exists[line=%d]\n", orderptr->ordercode,line); fclose(logfp); fclose(cfgfp); exit(1); } ordertail=ordertail->next; } ordertail->next=orderptr; memset(cfginfo,0x0,sizeof(cfginfo)); } fclose(cfgfp); fprintf(logfp,"ORDER INFO:\n"); orderptr=orderhead.next; while(orderptr) { fprintf(logfp,"%06d = [%s]\n",orderptr->ordercode,orderptr->orderinfo); orderptr=orderptr->next; } fflush(logfp); /************ GET REPLY INFO ***********************/ cfgfp=fopen(reply_fname,"r"); if(cfgfp==NULL) { fprintf(logfp,"Can't open %s for read[%d]\n",reply_fname,errno); fclose(logfp); exit(1); } fprintf(logfp,"REPLY INFO:\n"); line=0; memset(cfginfo,0x0,sizeof(cfginfo)); while(fgets(cfginfo,sizeof(cfginfo),cfgfp)) { line++; if(cfginfo[0]=='#' || cfginfo[0]=='\r' || cfginfo[0]=='\n') { memset(cfginfo,0x0,sizeof(cfginfo)); continue; } fprintf(logfp,"%s",cfginfo); if(strncmp(cfginfo,"RETN:",5) || cfginfo[9]!=':') { fprintf(logfp,"Incorrect cfg_info[line=%d]\n",line); fclose(cfgfp); fclose(logfp); exit(1); } replyptr=(struct reply_info *)malloc(sizeof(struct reply_info)); memset(replyptr,0x0,sizeof(struct reply_info)); replyptr->replycode=atoi(cfginfo+5); p=cfginfo+10; d=replyptr->replyinfo; if(*p!='[' || strchr(p,']')==NULL) { fprintf(logfp,"Incorrect cfg_info[line=%d]\n",line); fclose(cfgfp); fclose(logfp); exit(1); } while(*(++p)!=']') { if(*p=='\\') { p++; switch(*p) { case 'r': *d='\r'; break; case 'n': *d='\n'; break; case 't': *d='\t'; break; default: *d=*p; } } else *d=*p; d++; } if(d==replyptr->replyinfo) { fprintf(logfp,"Incorrect cfg_info[line=%d]\n",line); fclose(cfgfp); fclose(logfp); exit(1); } replyptr->next=replyhead.next; replyhead.next=replyptr; memset(cfginfo,0x0,sizeof(cfginfo)); } fclose(cfgfp); fflush(logfp); /************ GET QUERY INFO ***********************/ ret=get_query_cfg(query_fname); if(ret) { fprintf(logfp,"get_query_cfg()===%d\n",ret); fclose(logfp); exit(1); } disp_query_cfg(); /************ INIT COMM_PORT ***********************/ connid=tcp_connect(srvip, commport); if(connid<0) { fprintf(logfp,"socket() failed[%d]\n",errno); fclose(logfp); exit(1); } if(login_server(connid, hlrcode, hlrport, mgr_user, mgr_pswd, mgr_term)) { fprintf(logfp,"login_server() failed!\n"); fclose(logfp); exit(1); } fprintf(logfp,"login_server(%s) success!\n",hlrcode); gsmid = tcp_connect(gsmip, gsmport); sndid=gsmid; rcvid=gsmid; /*** LOGIN HLR ***/ sleep(1); enter[0]='\r'; enter[1]=0x00; while(1) { RcvFrmFlag(); if(strstr(replystr+STATION,"<")) { break; } if(strstr(replystr+STATION,"USERCODE")) { cusnd(gsmuser,strlen(gsmuser)); cusnd(enter,1); continue; } if(strstr(replystr+STATION,"PASSWORD")) { cusnd(gsmpswd,strlen(gsmpswd)); cusnd(enter,1); continue; } cusnd(enter,1); } fprintf(logfp,"LOGIN HLR,SUCCESS![%ld]\n",time(NULL)); fflush(logfp); /************** GET AN ORDER AND DEAL ********************/ waitnum=0; transid=2; cmdreqptr=(struct cmd_data_req *)tcpbuf.data; cmdreqptr->type=ONLY_GET; yy_time.rec_time = time(NULL); strcpy(yy_time.hlrcode, hlrcode); strcpy(yy_time.hlrport, hlrport); while(1) { int data_flag = 0; gettimeofday(&t1, NULL); if(send_req(connid,DECRYPT,TX_END,GETORDER,transid++,CMDREQLEN)<0) { fprintf(logfp,"send_req(%d) failed[%d]\n",connid,errno); break; } readlen = read_ack(connid, &tcpbuf); if(readlen != 0) { fprintf(logfp,"readnet(%d,8,%d)=%d failed!\n",connid,msglen-8,readlen); break; } gettimeofday(&t2, NULL); cmdackptr=(struct cmd_data_ack *)tcpbuf.data; data_flag = (get_length(cmdackptr->retn,4) == 0001); if(data_flag){ yy_time.rows ++; yy_time.tm4get += time_diff1(t1, t2); } printf("RCV:%s~\n",(char *)&tcpbuf); ret=exec_cmd(); gettimeofday(&t1, NULL); if(data_flag){ yy_time.tm4exc += time_diff1(t2, t1); } printf("EXEC_CMD===========%d\n",ret); if(ret<0) { fprintf(logfp,"exec_cmd() failed!\n"); break; } time(&t); yy_time_log(t); tv=localtime(&t); if(today!=tv->tm_mday) { fclose(logfp); memset(logfilename,0x0,sizeof(logfilename)); sprintf(logfilename,"%s/erc%04d%02d%02d.%s.%s",logdir, tv->tm_year+1900,tv->tm_mon+1,tv->tm_mday,hlrcode,hlrport); logfp=fopen(logfilename,"a"); if(logfp==NULL) { printf("can't open %s for LOG!\n",logfilename); exit(1); } today=tv->tm_mday; } fflush(logfp); } fclose(logfp); close(connid); return 0; }
void * AP_CCCI_RX (void* lpParameter) { char buf_ack [BUF_SIZE] = {0}; char buf_log [BUF_SIZE] = {0}; int rd_len=0, wr_len=0; LOGD(TAG "Enter AP_CCCI_RX()\n"); for (;;) { #if 0 #ifdef MTK_ENABLE_MD2 if(g_mdFlag==1) rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); if(g_mdFlag==2) rd_len = read_ack (g_fd_atcmdmd2, buf_ack, BUF_SIZE); #else rd_len = read_ack (g_fd_atcmd, buf_ack, BUF_SIZE); #endif #endif if(g_mdFlag == 1) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "1")) { #ifndef EVDO_DT_SUPPORT rd_len = read_ack(g_fd_atcmdmd_dt, buf_ack, BUF_SIZE); #endif } else { if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } } #else if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } #endif } else if(g_mdFlag == 2) { #if defined(MTK_EXTERNAL_MODEM_SLOT) if(!strcmp(MTK_EXTERNAL_MODEM_SLOT, "2")) { #ifndef EVDO_DT_SUPPORT rd_len = read_ack(g_fd_atcmdmd_dt, buf_ack, BUF_SIZE); #endif } else { if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } } #else if(is_support_modem(1)){ rd_len = read_ack(g_fd_atcmd, buf_ack, BUF_SIZE); }else if(is_support_modem(2)){ rd_len = read_ack(g_fd_atcmdmd2, buf_ack, BUF_SIZE); } #endif } if (rd_len>0) { memcpy (buf_log, buf_ack, rd_len); buf_log[rd_len] = '\0'; LOGD(TAG "AP_CCCI_RX: %s, rd_len = %d\n", buf_log, rd_len); ACK_Pre_Process(buf_log); wr_len = write_chars (g_fd_uart, buf_ack, rd_len); if (wr_len != rd_len) LOGE(TAG "AP_CCCI_RX: wr_len != rd_len\n"); } } //pthread_exit(NULL); }