void tst_que(void) { int r,q; char str[]="ABCD\n"; struct msg_head msg; char *c; syscall_wait(10); q = syscall_que_lookup(QUENAME); if(q<0) { display_puts("que lookup="); long2hex(-q,s); display_puts(s); display_puts("\n"); return; } for(c=str;;c++) { msg.size=msg_sizeof(msg); msg.service=0; msg.command=0; msg.arg=*c; r = syscall_que_put(q, &msg); if(r<0) { display_puts("que put="); long2hex(-r,s); display_puts(s); display_puts("\n"); break; } if(*c=='\n') break; } }
int cdfs_init(void) { int rc; if(cdfs_queid != 0) return 0; for(;;) { rc = syscall_que_lookup(CDFS_QNM_CDFS); if(rc==ERRNO_NOTEXIST) { syscall_wait(10); continue; } if(rc<0) { cdfs_queid = 0; display_puts("cdfs_init srvq="); long2hex(-rc,s); display_puts(s); display_puts("\n"); return rc; } cdfs_queid = rc; break; } //display_puts("cdfs_init done\n"); return 0; }
int display_putc(int chr) { struct msg_head msg; int r; if(display_queid==0) { r=display_init(); if(r<0) return r; } msg.size=sizeof(struct msg_head); msg.service=DISPLAY_SRV_DISPLAY; msg.command=DISPLAY_CMD_PUTC; msg.arg=chr; for(;;) { r=message_send(display_queid, &msg); if(r!=ERRNO_OVER) break; syscall_wait(10); } if(r<0) { syscall_puts("putc sndcmd="); long2hex(-r,s); syscall_puts(s); syscall_puts("\n"); return r; } return 0; }
static void dump(char *addr) { int i,j; for(j=0;j<2;j++) { long2hex((unsigned long)addr,s); display_puts(s); for(i=0;i<16;i++,addr++) { byte2hex(*addr,s); display_puts(" "); display_puts(s); } display_puts("\n"); syscall_wait(50); } }
static void *pci_scan_bios(void) { unsigned char *bios_addr; for(bios_addr = (void*)CFG_MEM_BIOSSTART; (unsigned long)bios_addr < CFG_MEM_BIOSMAX-sizeof(struct pci_bios) ; bios_addr++ ) { if(memcmp(bios_addr,"_32_",4)!=0) continue; struct pci_bios *info=(void*)bios_addr; if(info->revision!=0) continue; if(info->length!=(unsigned char)1) continue; unsigned char i,checksum=0; for(i=0;i<sizeof(struct pci_bios);i++) { checksum += bios_addr[i]; } if(checksum!=info->checksum) continue; display_puts("entry="); long2hex(info->entry,s); display_puts(s); display_puts(",rev="); int2dec(info->revision,s); display_puts(s); display_puts(",len="); int2dec(info->length,s); display_puts(s); display_puts(",chk="); byte2hex(info->checksum,s); display_puts(s); display_puts("\n"); return (void*)info->entry; //display_puts("."); //syscall_wait(100); } display_puts("PCI BIOS is not found\n"); dump((void*)CFG_MEM_BIOSSTART); return 0; }
void tst_key(void) { int r; r=keyboard_init(); if(r<0) { display_puts("kbd init="); long2hex(-r,s); display_puts(s); display_puts("\n"); return; } for(;;) { r=keyboard_getcode(); if(r<0) { display_puts("kbd getcode="); int2dec(-r,s); display_puts(s); display_puts("\n"); return; } /* display_puts("key="); byte2hex(r,s); display_puts(s); */ s[0]=r; s[1]='1'; s[2]=0; display_puts(s); /* int2dec(r,s); display_puts(s); display_puts("1"); */ } }
int display_init(void) { int r; if(display_queid != 0) return 0; display_queid = environment_get_display((void*)CFG_MEM_USERARGUMENT); if(display_queid != 0) return 0; for(;;) { r = syscall_que_lookup(DISPLAY_QNM_DISPLAY); if(r==ERRNO_NOTEXIST) { syscall_wait(10); continue; } if(r<0) { syscall_puts("dsp_init srvq err="); long2hex(-r,s); syscall_puts(s); syscall_puts("\n"); return r; } display_queid = r; environment_make_display((void*)CFG_MEM_USERARGUMENT, display_queid); break; } /* syscall_puts("dspqids q="); int2dec(display_queid,s); syscall_puts(s); syscall_puts(","); int2dec(display_clientq,s); syscall_puts(s); syscall_puts("\n"); */ return 0; }
int mouse_request_code(int mode) { union mou_msg msg; int r; if(mou_queid==0) { r=mouse_init(); if(r<0) return r; } if(mou_requested) { return 0; } msg.req.h.size=sizeof(union mou_msg); msg.req.h.service=MOU_SRV_MOUSE; msg.req.h.command=MOU_CMD_GETCODE; if(mode) msg.req.queid=mou_clientq; else msg.req.queid=0; /* int2dec(msg.req.queid,s); display_puts(s); */ r=message_send(mou_queid, &msg); if(r<0) { display_puts("getcode sndcmd="); long2hex(-r,s); display_puts(s); display_puts("\n"); return r; } mou_requested=1; return 0; }
int mouse_init(void) { int r; int retry=100; if(mou_queid != 0) return 0; for(;;) { r = syscall_que_lookup(MOU_QNM_MOUSE); if(r==ERRNO_NOTEXIST) { syscall_wait(10); if(retry--) continue; return -1; } if(r<0) { mou_queid = 0; display_puts("Cmou_init srvq="); long2hex(-r,s); display_puts(s); display_puts("\n"); return r; } mou_queid = r; break; } mou_clientq=environment_getqueid(); /* display_puts("Ckbdqids q="); int2dec(mou_queid,s); display_puts(s); display_puts(","); int2dec(mou_clientq,s); display_puts(s); display_puts("\n"); */ return 0; }
void trans_layer::received_msg(sip_msg* msg) { #define DROP_MSG \ delete msg;\ return int err = parse_sip_msg(msg); DBG("parse_sip_msg returned %i\n",err); if(err){ DBG("Message was: \"%.*s\"\n",msg->len,msg->buf); DBG("dropping message\n"); DROP_MSG; } assert(msg->callid && get_cseq(msg)); if(!msg->callid || !get_cseq(msg)){ DBG("Call-ID or CSeq header missing: dropping message\n"); DROP_MSG; } unsigned int h = hash(msg->callid->value, get_cseq(msg)->num_str); trans_bucket* bucket = get_trans_bucket(h); sip_trans* t = NULL; bucket->lock(); switch(msg->type){ case SIP_REQUEST: if((t = bucket->match_request(msg)) != NULL){ if(msg->u.request->method != t->msg->u.request->method){ // ACK matched INVITE transaction DBG("ACK matched INVITE transaction\n"); err = update_uas_request(bucket,t,msg); if(err<0){ DBG("trans_layer::update_uas_trans() failed!\n"); // Anyway, there is nothing we can do... } else if(err == TS_TERMINATED){ // do not touch the transaction anymore: // it could have been deleted !!! // should we forward the ACK to SEMS-App upstream? Yes } } else { DBG("Found retransmission\n"); retransmit(t); } } else { string t_id; sip_trans* t = NULL; if(msg->u.request->method != sip_request::ACK){ // New transaction t = bucket->add_trans(msg, TT_UAS); t_id = int2hex(h).substr(5,string::npos) + ":" + long2hex((unsigned long)t); } bucket->unlock(); // let's pass the request to // the UA. assert(ua); ua->handle_sip_request(t_id.c_str(),msg); if(!t){ DROP_MSG; } //Else: // forget the msg: it will be // owned by the new transaction return; } break; case SIP_REPLY: if((t = bucket->match_reply(msg)) != NULL){ // Reply matched UAC transaction DBG("Reply matched an existing transaction\n"); if(update_uac_trans(bucket,t,msg) < 0){ ERROR("update_uac_trans() failed, so what happens now???\n"); break; } // do not touch the transaction anymore: // it could have been deleted !!! } else { DBG("Reply did NOT match any existing transaction...\n"); DBG("reply code = %i\n",msg->u.reply->code); if( (msg->u.reply->code >= 200) && (msg->u.reply->code < 300) ) { bucket->unlock(); // pass to UA assert(ua); ua->handle_sip_reply(msg); DROP_MSG; } } break; default: ERROR("Got unknown message type: Bug?\n"); break; } // unlock_drop: bucket->unlock(); DROP_MSG; }
int trans_layer::send_request(sip_msg* msg, char* tid, unsigned int& tid_len) { // Request-URI // To // From // Call-ID // CSeq // Max-Forwards // Via // Contact // Supported / Require // Content-Length / Content-Type assert(transport); tid_len = 0; if(set_next_hop(msg->route,msg->u.request->ruri_str, &msg->remote_ip) < 0){ // TODO: error handling DBG("set_next_hop failed\n"); //delete msg; return -1; } // assume that msg->route headers are not in msg->hdrs msg->hdrs.insert(msg->hdrs.begin(),msg->route.begin(),msg->route.end()); int request_len = request_line_len(msg->u.request->method_str, msg->u.request->ruri_str); char branch_buf[BRANCH_BUF_LEN]; compute_branch(branch_buf,msg->callid->value,msg->cseq->value); cstring branch(branch_buf,BRANCH_BUF_LEN); string via(transport->get_local_ip()); if(transport->get_local_port() != 5060) via += ":" + int2str(transport->get_local_port()); request_len += via_len(stl2cstr(via),branch); request_len += copy_hdrs_len(msg->hdrs); string content_len = int2str(msg->body.len); request_len += content_length_len(stl2cstr(content_len)); request_len += 2/* CRLF end-of-headers*/; if(msg->body.len){ request_len += msg->body.len; } // Allocate new message sip_msg* p_msg = new sip_msg(); p_msg->buf = new char[request_len]; p_msg->len = request_len; // generate it char* c = p_msg->buf; request_line_wr(&c,msg->u.request->method_str, msg->u.request->ruri_str); via_wr(&c,stl2cstr(via),branch); copy_hdrs_wr(&c,msg->hdrs); content_length_wr(&c,stl2cstr(content_len)); *c++ = CR; *c++ = LF; if(msg->body.len){ memcpy(c,msg->body.s,msg->body.len); // Not needed by now as the message is finished //c += body.len; } // and parse it if(parse_sip_msg(p_msg)){ ERROR("Parser failed on generated request\n"); ERROR("Message was: <%.*s>\n",p_msg->len,p_msg->buf); delete p_msg; return MALFORMED_SIP_MSG; } memcpy(&p_msg->remote_ip,&msg->remote_ip,sizeof(sockaddr_storage)); DBG("Sending to %s:%i <%.*s>\n", get_addr_str(((sockaddr_in*)&p_msg->remote_ip)->sin_addr).c_str(), ntohs(((sockaddr_in*)&p_msg->remote_ip)->sin_port), p_msg->len,p_msg->buf); trans_bucket* bucket = get_trans_bucket(p_msg->callid->value, get_cseq(p_msg)->num_str); bucket->lock(); int send_err = transport->send(&p_msg->remote_ip,p_msg->buf,p_msg->len); if(send_err < 0){ ERROR("Error from transport layer\n"); delete p_msg; } else { sip_trans* t = bucket->add_trans(p_msg,TT_UAC); if(p_msg->u.request->method == sip_request::INVITE){ // if transport == UDP t->reset_timer(STIMER_A,A_TIMER,bucket->get_id()); // for any transport type t->reset_timer(STIMER_B,B_TIMER,bucket->get_id()); } else { // if transport == UDP t->reset_timer(STIMER_E,E_TIMER,bucket->get_id()); // for any transport type t->reset_timer(STIMER_F,F_TIMER,bucket->get_id()); } string t_id = int2hex(bucket->get_id()).substr(5,string::npos) + ":" + long2hex((unsigned long)t); memcpy(tid,t_id.c_str(),t_id.length()); tid_len = t_id.length(); } bucket->unlock(); return send_err; }