/* * ======== ceapp_exit ======== */ void ceapp_exit() { /* teardown the codecs and the engine */ if (decHandle != NULL) { SPHDEC1_delete(decHandle); traceDump(ceHandle); } if (ceHandle != NULL) { Engine_close(ceHandle); } }
/* * ======== ceapp_init ======== */ int ceapp_init(void *params) { int status = -1; /* nonzero means failure */ /* initialize Codec Engine runtime first */ /* This function has been moved to main() in main.c */ //CERuntime_init(); /* reset, load, and start DSP Engine */ if ((ceHandle = Engine_open(engineName, NULL, NULL)) == NULL) { printf("CEapp-> ERROR: can't open engine %s\n", engineName); goto init_end; } else { printf("CEapp-> Engine Opened: %s\n", engineName); } /* dump contents of DSP trace -- this is a "pull" trace dumping: we read * DSP's trace log whenever we think there might be something there. */ traceDump(ceHandle); /* allocate and initialize audio decoder on the engine */ decHandle = SPHDEC1_create(ceHandle, decoderName, params); if (decHandle == NULL) { printf("CEapp-> ERROR: can't open codec %s\n", decoderName); goto init_end; } else { printf("CEapp-> Codec opened %s\n", decoderName); } traceDump(ceHandle); status = 0; /* success */ init_end: return status; }
// process characters at a time for commands char command(void) { S16 ret=0; IPADDR t; U8 *u; readln_from_a_file((FILE*)stdin, command_buffer, CMD_MAX_SIZE); yprintf("command in = %s\n",command_buffer); if(command_buffer[0]=='?') { // Attach to service printf("Supported Commands:\n"); printf(" r - restart\n"); printf(" e - drop next tunnel rx packet\n"); printf(" m - check status of memory allocator\n"); printf(" p - change port\n"); printf(" s - status\n"); printf(" y - startup proxy\n"); printf(" c - connect\n"); printf(" w - send wakup command (ping server and clients)\n"); printf(" i - send direct message (specify uid and msg)\n"); #if defined(WEB_SSL) printf(" ssl on - enable ssl\n"); printf(" ssl off - disable ssl\n"); #endif printf(" f - files from share target (fl - directory list...)\n"); printf(" d - Get device List (only works if yoicsid client.)\n"); printf("\n q to quit bcaster\n"); printf("\n x to exit right now without cleanup.\n"); } else if(command_buffer[0]=='r') { // Attach to service printf("Reconnect to Weaved Service...\n"); Yoics_reconnect(); //printf("current state %s\n",server_state_string[state]); } else if(command_buffer[0]=='p') { printf("Swapping local port to %d\n",Yoics_Change_Port(0)); } else if(command_buffer[0]=='w') { printf("Wakeup Command\n"); send_ping(PING_STANDARD); Yoics_Session_Force_Ping(); #if defined(TRACE_LOG) traceDump(); // Tracedump just for test #endif } else if (command_buffer[0]=='c') { // connect printf("sending connect request for "); print_uid(Remote_Address); printf("\n"); //Session_create(&Remote_Address, 0); ////+++ remote address right? #if defined(BCASTER) ret=Yoics_Session_create(Remote_Address); if(-1== ret ) { printf("Initiate session create faild\n"); } else if(-2==ret) { printf("Initiate session create faild, no slots left\n"); } else printf("OK ret= %d\n",ret); #endif #if defined(BUILD_SHARE) new_share=Share_Connect(Remote_Address,&share_app_callback); if(0== new_share ) { printf("Initiate session create faild\n"); } else printf("OK ret= %d\n",ret); #endif //yoics_connect(Remote_Address); } else if (command_buffer[0]=='m') { #if ALLOC_DEBUG alloc_check(); #else alloc_stat(); #endif alloc_pool_check(pool); } else if (command_buffer[0]=='s') { #if defined(WEB_SSL) if (!strcmp(command_buffer,"ssl on")) { printf("Turn on SSL\n"); // // Set the web port to ssl port // webPort = WEB_PORT_SSL; // // Enable SSL module Yoics_Set_SSL(SSL_ENABLE); } else if (!strcmp (command_buffer, "ssl off")) { printf("Turn off SSL\n"); // // Set the web port to non SSL port // webPort = WEB_PORT; // // Disable SSL module // Yoics_Set_SSL (SSL_DISABLE); } else #endif { t=Yoics_Get_Current_Server(); u=Yoics_Current_UID(); printf("server state is %d -- 0)Uconn 1)rstart 2)NATchk 3)ReqAuth 4)ID 5)Conn\n",Yoics_Server_Connection_State()); printf(" server is %d.%d.%d.%d:%d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,(U16)Yoics_Get_Current_Server_Port()); printf(" key hash is %x:%x\n",secret[0],secret[1]); printf(" server spi is 0x%X\n",(unsigned int)Yoics_Return_Server_SPI()); printf("Our UID is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]); printf("Our Serial Number is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", serial_num[0],serial_num[1],serial_num[2],serial_num[3],serial_num[4],serial_num[5], serial_num[6],serial_num[7]); t=Yoics_Get_Our_Bound_IP(); printf("Our bound ip:port is %d.%d.%d.%d:%d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,Yoics_Get_Our_Bound_Port()); t=Yoics_Get_Our_Mapped_IP(); printf("Our mapped ip:port is %d.%d.%d.%d:%d - UPNP/NAT-PMP mapped port is %d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,Yoics_Get_Our_Mapped_Port(),parameters.upnp_port); printf("Last server hearbeat %u seconds ago\n",(U32)((U32)second_count()-(U32)server_hearbeat)); printf("Our NAT type is %d\n",Yoics_Return_NAT_Type()); printf("Forward Port is %d\n\n",parameters.forward_port); alloc_stat(); printf("\nActive Sessions %d\n",active_sessions); printf("\nSession List\n"); Yoics_session_list(); printf("\nProxy Status\n"); proxy_status(); } } else if (command_buffer[0]=='e') { //printf("Drop next tun data packet.\n"); //tunnel_drop(tun_num); } else if (command_buffer[0]=='y') { if(sindex) { if(proxy_local_port==0) proxy_local_port=5959; printf("Starting Proxy on port %d.\n",proxy_local_port); if(proxy_client_start(proxy_ip,proxy_local_port, restrict_connect_ip, sindex)) //if(proxy_start(proxy_ip,proxy_local_port)) printf("Proxy started.\n"); else printf("proxy startup failed.\n"); } else { printf("must be connected to peer first\n"); } } else if (command_buffer[0]=='d') { printf("Device List:\n"); #if !defined(BCASTER) if(YOICS_SERVER_CONNECTED==Yoics_Server_Connection_State()) { DEVICE devlist[10]; char server_name[32]; int tt; IPADDR answer; // Get current server IP and make it into a string answer=Yoics_Get_Current_Server(); sprintf(server_name,"%d.%d.%d.%d",answer.ipb1,answer.ipb2,answer.ipb3,answer.ipb4); tt=Yoics_Get_Device_List(server_name, webPort, 5000, devlist, 10, 1); printf("found %d entries\n",tt); } else printf("Must be connected to service to issue this command\n"); #endif } else if (command_buffer[0]=='z') { U8* crash; yprintf("Force SIG 11:\n"); crash=0; *crash="c"; // This is correct, it forces a crash! Ignore this warning in compile //session_list(); } else if (command_buffer[0]=='q') { ret=EXIT; } else if (command_buffer[0]=='x') { DEBUG4("Free Pool x\n"); free_pool(); #if defined(TRACE_LOG) traceCleanup(); #endif exit(0); ret=EXIT; } else if (command_buffer[0]=='i') { int len; U8* tptr; char tpack[255]; U8 tuid[32]; YOICSPACKET *pkt; pkt=(YOICSPACKET*)tpack; // // Create a map peer // pkt->packet_type = htons(PING_MSG); pkt->source = htons(TARGET_FORWARD); // not done yet len = sizeof(YOICSPACKET); pkt->salt = 0; pkt->spi = 0; tptr=pkt->data; // // Add our UID // tptr=yoics_add_data(tptr,CLIENTUID,my_uid,UID_SIZE); len+=UID_SIZE+sizeof(DATATYPE); // // Add Null Type to finish the message // yoics_add_data(tptr,NULLTYPE,0,0); len+=sizeof(DATATYPE); // // send direct message using packet forwarder // UID_Extract(&tuid[0],"80:00:00:05:46:00:26:e7"); send_packet_forward(tuid, (U8*)tpack ,len); } else { yprintf("unknown command = %s\n",command_buffer); } return((S8)ret); }