// Main function for STUN listener thread for media STUN requests.
void *stun_listen_main(void *arg) {
	char		buf[STUN_MAX_MESSAGE_SIZE + 1];
	int		data_size;
	
	t_socket_udp *sock = (t_socket_udp *)arg;
	
	while(true) {
		try {
			data_size = sock->recv(buf, STUN_MAX_MESSAGE_SIZE + 1);
		} catch (int err) {
			string msg("Failed to receive STUN response for media.\n");
			msg += get_error_str(err);
			log_file->write_report(msg, "::stun_listen_main",
				LOG_NORMAL, LOG_CRITICAL);
				
			// The request will timeout, no need to send a response now.
				
			return NULL;
		}
		
		StunMessage m;
		
		if (!stunParseMessage(buf, data_size, m, false)) {
			log_file->write_report("Faulty STUN message", "::stun_listen_main");
			continue;
		}
		
		log_file->write_header("::stun_listen_main", LOG_STUN);
		log_file->write_raw("Received: ");
		log_file->write_raw(stunMsg2Str(m));
		log_file->write_footer();
	
		evq_trans_mgr->push_stun_response(&m, 0, 0);
	}
}
示例#2
0
void write_cmd_to_socket(t_cmd_code opcode, bool immediate, const string &args) {
	string name = sys_config->get_dir_user();
	name += '/';
	name += CMD_SOCKNAME;

	try {
		t_socket_local sock_cmd;
		sock_cmd.connect(name);
		sock_cmd.write(&opcode, sizeof(opcode));
		sock_cmd.write(&immediate, sizeof(immediate));
		int len = args.size() + 1;
		sock_cmd.write(&len, sizeof(len));
		char *buf = strdup(args.c_str());
		MEMMAN_NEW(buf);
		sock_cmd.write(buf, len);
		MEMMAN_DELETE(buf);
		free(buf);
	}
	catch (int e) {
		// This function will be called from Twinkle when it
		// notices another Twinkle is already running. In that
		// case this process does not have a log file. So write
		// errors to stderr
		cerr << "Failed to send " << cmd_code2str(opcode) << " command to " << name << endl;
		cerr << get_error_str(e) << endl;
	}
}
示例#3
0
int check_sms_report( struct incame_sms *sms )
{
	struct sms_msg *sms_messg;
	str *s1, *s2;
	int old;
	int res;

	LM_DBG("Report for sms number %d.\n",sms->sms_id);
	res=relay_report_to_queue( sms->sms_id, sms->sender, sms->ascii[0], &old);
	if (res==3) { /* error */
		/* the sms was confirmed with an error code -> we have to send a
		message to the SIP user */
		s1 = get_error_str(sms->ascii[0]);
		s2 = get_text_from_report_queue(sms->sms_id);
		sms_messg = get_sms_from_report_queue(sms->sms_id);
		send_error( sms_messg, s1->s, s1->len, s2->s, s2->len);
	} else if (res==1 && sms->ascii[0]==48 && old!=48) { /* provisional 48 */
		/* the sms was provisional confirmed with a 48 code -> was stored
		by SMSC -> no further real-time tracing possible */
		s2 = get_text_from_report_queue(sms->sms_id);
		sms_messg = get_sms_from_report_queue(sms->sms_id);
		send_error( sms_messg, STORED_NOTE, STORED_NOTE_LEN, s2->s, s2->len);
	} else if (res==2 && old==48) {
		/* we received OK for a SMS that had received prev. an 48 code.
		The note that we send for 48 has to be now clarify */
		s2 = get_text_from_report_queue(sms->sms_id);
		sms_messg = get_sms_from_report_queue(sms->sms_id);
		send_error( sms_messg, OK_MSG, OK_MSG_LEN, s2->s, s2->len);
	}
	if (res>1) /* final response */
		remove_sms_from_report_queue(sms->sms_id);

	return 1;
}
void t_media_stun_trans::retransmit(void) {
	// Retransmit the STUN request
	StunAtrString stun_pass;
	stun_pass.sizeValue = 0;
	char m[STUN_MAX_MESSAGE_SIZE];
	int msg_size = stunEncodeMessage(*request, m, STUN_MAX_MESSAGE_SIZE, stun_pass, false);
	
	try {
		sock->sendto(destinations.front().ipaddr, destinations.front().port, 
			m, msg_size);
	} catch (int err) {
		string msg("Failed to send STUN request for media.\n");
		msg += get_error_str(err);
		log_file->write_report(msg, "::t_media_stun_trans::retransmit",
			LOG_NORMAL, LOG_CRITICAL);
			
		StunMessage *resp;
		resp = stunBuildError(*request, 500, "Could not send request");

		evq_trans_layer->push_stun_response(resp, tuid, id);
		MEMMAN_DELETE(resp);
		delete resp;
			
		return;
	}
	
	num_transmissions++;
}
示例#5
0
/**
 * 装载TTA音乐文件 
 *
 * @param spath 短路径名
 * @param lpath 长路径名
 *
 * @return 成功时返回0
 */
static int tta_load(const char *spath, const char *lpath)
{
	__init();

	if (tta_read_tag(spath) != 0) {
		__end();
		return -1;
	}

	if (g_buff != NULL) {
		free(g_buff);
		g_buff = NULL;
	}
	g_buff = calloc(TTA_BUFFER_SIZE, sizeof(*g_buff));
	if (g_buff == NULL) {
		__end();
		return -1;
	}

	if (open_tta_file(spath, &ttainfo, 0, g_io_buffer_size) < 0) {
		dbg_printf(d, "TTA Decoder Error - %s", get_error_str(ttainfo.STATE));
		close_tta_file(&ttainfo);
		return -1;
	}

	if (player_init(&ttainfo) != 0) {
		__end();
		return -1;
	}

	if (ttainfo.BPS == 0) {
		__end();
		return -1;
	}

	g_info.samples = ttainfo.DATALENGTH;
	g_info.duration = (double) ttainfo.LENGTH;
	g_info.sample_freq = ttainfo.SAMPLERATE;
	g_info.channels = ttainfo.NCH;
	g_info.filesize = ttainfo.FILESIZE;

	if (xAudioInit() < 0) {
		__end();
		return -1;
	}

	if (xAudioSetFrequency(ttainfo.SAMPLERATE) < 0) {
		__end();
		return -1;
	}

	xAudioSetChannelCallback(0, tta_audiocallback, NULL);

	generic_lock();
	g_status = ST_LOADED;
	generic_unlock();

	return 0;
}
示例#6
0
void *listen_cmd(void *arg) {
	t_socket_local *sock_cmd = (t_socket_local *)arg;
	string log_msg;
	
	while (true) {
		try {
			int fd = sock_cmd->accept();
			t_socket_local sock_client(fd);
			exec_cmd(sock_client);
		}
		catch (int e) {
			log_msg = "Accept failed on socket.\n";
			log_msg += get_error_str(e);
			log_msg += "\n";
			log_file->write_report(log_msg, "cmdsocket::listen_cmd", LOG_NORMAL, 
				LOG_WARNING);
			return NULL;
		}
	}
}
示例#7
0
文件: PrlStat.cpp 项目: OpenVZ/prlctl
static PRL_RESULT perfstats_callback(PRL_HANDLE handle, void *user_data, PRL_EVENT_TYPE process_type)
{
	PrlHandle clean(handle);
	PRL_RESULT ret;
	PRL_EVENT_TYPE e_type;

	const CmdParamData &param = *(const CmdParamData*)user_data;

	ret = PrlEvent_GetType(handle, &e_type);
	if (PRL_FAILED(ret)) {
		prl_log(L_DEBUG, "Warning! PrlSrv_Logoff failed: %s", get_error_str(ret).c_str());
		return PRL_ERR_SUCCESS;
	}

	if (e_type != process_type)
		return PRL_ERR_SUCCESS;

	print_perfstats(handle, param);

	if (s_evt)
		s_evt->Signal();

	return PRL_ERR_SUCCESS;
}
示例#8
0
void t_audio_tx::play_pcm(unsigned char *buf, unsigned short len, bool only_3rd_party) {
	int status;
	//struct timeval debug_timer, debug_timer_prev;

	unsigned char *playbuf = buf;

	// If there is only sound from the 3rd party in a 3-way, then check
	// if there is still enough sound in the buffer of the DSP to be
	// played. If not, then play out the sound from the 3rd party only.
	if (only_3rd_party) {
		/* Does not work on all ALSA implementations.
		if (playback_device->get_buffer_space(false) < soundcard_buf_size - len) {
		*/
		if (!playback_device->play_buffer_underrun()) {
			// There is still sound in the DSP buffers to be
			// played, so let's wait. Maybe in the next cycle
			// an RTP packet from the far-end will be received.
			return;
		}
	}

	// If we are in a 3-way then send the samples to the peer audio
	// receiver for mixing
	if (!only_3rd_party && is_3way && peer_rx_3way) {
		peer_rx_3way->post_media_peer_tx_3way(buf, len, sc_sample_rate);
	}

	// If we are in a 3-way conference and we are not the mixer then
	// send the sound samples to the mixer
	if (is_3way && !is_3way_mixer) {
		if (peer_tx_3way) {
			peer_tx_3way->post_media_peer_tx_3way(buf, len, sc_sample_rate);
			return;
		} else {
			// There is no peer.
			return;
		}
	}

	// Mix audio for 3-way conference
	if (is_3way && is_3way_mixer) {
		if (media_3way_peer_tx->get(mix_buf_3way, len)) {
			short *mix_sb = (short *)mix_buf_3way;
			short *sb = (short *)buf;
			for (int i = 0; i < len / 2; i++) {
				mix_sb[i] = mix_linear_pcm(sb[i], mix_sb[i]);
			}

			playbuf = mix_buf_3way;
		}
	}

	// Fill jitter buffer before playing
	if (load_jitter_buf) {
		if (jitter_buf_len + len < JITTER_BUF_SIZE(sc_sample_rate)) {
			memcpy(jitter_buf + jitter_buf_len, playbuf, len);
			jitter_buf_len += len;
		} else {
			// Write the contents of the jitter buffer to the DSP.
			// The buffers in the DSP will now function as jitter
			// buffer.
			status = playback_device->write(jitter_buf, jitter_buf_len);
			if (status != jitter_buf_len) {
				string msg("Writing to dsp failed: ");
				msg += get_error_str(errno);
				log_file->write_report(msg, "t_audio_tx::play_pcm",
					LOG_NORMAL, LOG_CRITICAL);
			}

			// Write passed sound samples to DSP.
			status = playback_device->write(playbuf, len);
			if (status != len) {
				string msg("Writing to dsp failed: ");
				msg += get_error_str(errno);
				log_file->write_report(msg, "t_audio_tx::play_pcm",
					LOG_NORMAL, LOG_CRITICAL);
			}

			load_jitter_buf = false;
		}

		return;
	}

	// If buffer on soundcard is empty, then the jitter buffer needs
	// to be refilled. This should only occur when no RTP packets
	// have been received for a while (silence suppression or packet loss)
	/*
	 * This code does not work on all ALSA implementations, e.g. ALSA via pulse audio
	int bufferspace = playback_device->get_buffer_space(false);
	if (bufferspace == soundcard_buf_size && len <= JITTER_BUF_SIZE(sc_sample_rate)) {
	*/
	if (playback_device->play_buffer_underrun()) {
		memcpy(jitter_buf, playbuf, len);
		jitter_buf_len = len;
		load_jitter_buf = true;
		log_file->write_header("t_audio_tx::play_pcm", LOG_NORMAL, LOG_DEBUG);
		log_file->write_raw("Audio tx line ");
		log_file->write_raw(get_line()->get_line_number()+1);
		log_file->write_raw(": jitter buffer empty.\n");
		log_file->write_footer();
		return;
	}

	// If the play-out buffer contains the maximum number of
	// packets then start skipping packets to prevent
	// unacceptable delay.
	// This can only happen if the thread did not get
	// processing time for a while and RTP packets start to
	// pile up.
	// Or if a soundcard plays out the samples at just less then
	// the requested sample rate.
	/* Not needed anymore, the ::run loop already discards incoming RTP packets
	   with a late timestamp. This seems to solve the slow soundcard problem
	   better. The solution below caused annoying ticks in the playout.
	   
	if (soundcard_buf_size - bufferspace > JITTER_BUF_SIZE + len) {
		log_file->write_header("t_audio_tx::play_pcm", LOG_NORMAL, LOG_DEBUG);
		log_file->write_raw("Audio tx line ");
		log_file->write_raw(get_line()->get_line_number()+1);
		log_file->write_raw(": jitter buffer overflow: ");
		log_file->write_raw(bufferspace);
		log_file->write_raw(" bytes.\n");
		log_file->write_footer();
		return;
	}
	*/

	// Write passed sound samples to DSP.
	status = playback_device->write(playbuf, len);
	
	if (status != len) {
		string msg("Writing to dsp failed: ");
		msg += get_error_str(errno);
		log_file->write_report(msg, "t_audio_tx::play_pcm",
			LOG_NORMAL, LOG_CRITICAL);
		return;
	}
}
/// Generate exception of T_seh_exception type inherited from std::runtime_error
void trans_func(unsigned int error_code, EXCEPTION_POINTERS* pExp) {
    throw seh::T_seh_exception(get_error_str(error_code));
}
示例#10
0
文件: PrlStat.cpp 项目: OpenVZ/prlctl
static PRL_RESULT print_perfstats(PRL_HANDLE handle, const CmdParamData &param)
{
	(void)param;
	unsigned int param_count;
	PRL_RESULT ret = PrlEvent_GetParamsCount(handle, &param_count);
	if (PRL_FAILED(ret))
		return prl_err(ret, "PrlEvent_GetParamsCount returned the following error: %s",
				get_error_str(ret).c_str());

	if (!param_count)
		return PRL_ERR_SUCCESS;

	// Print VM uuid if necessary
	if (param.list_all) {
		char uuid[NORMALIZED_UUID_LEN + 1] = {0};
		PRL_UINT32 size = sizeof(uuid);
		PRL_HANDLE hVm;
		if (PRL_SUCCEEDED(PrlEvent_GetVm(handle, &hVm))) {
			PrlVmCfg_GetUuid(hVm, uuid, &size);
			PrlHandle_Free(hVm);
		}
		printf("%s\n", uuid);
	}
	for (unsigned int ndx = 0; ndx < param_count; ++ndx) {
		PrlHandle hPrm;
		ret = PrlEvent_GetParam(handle, ndx, hPrm.get_ptr());
		if (PRL_FAILED(ret))
			return prl_err(ret, "PrlEvent_GetParam returned the following error: %s",
					get_error_str(ret).c_str());

		char name_buff[1024];
		unsigned int len = sizeof(name_buff) - 1;
		ret = PrlEvtPrm_GetName(hPrm.get_handle(), name_buff, &len);
		if (PRL_FAILED(ret))
			return prl_err(ret, "PrlEvtPrm_GetName returned the following error: %s",
					get_error_str(ret).c_str());
		char val_buff[1024];
		len = sizeof(val_buff) - 1;
		val_buff[len] = 0;

		PRL_PARAM_FIELD_DATA_TYPE nFieldType = PFD_UNKNOWN;
		PrlEvtPrm_GetType(hPrm.get_handle(), &nFieldType);
		if (nFieldType == PFD_BINARY) {
			if (strncmp(name_buff, PRL_NET_CLASSFUL_TRAFFIC_PTRN, sizeof(PRL_NET_CLASSFUL_TRAFFIC_PTRN) - 1) == 0) {
				PRL_STAT_NET_TRAFFIC net_stat_buf;
				len = sizeof(PRL_STAT_NET_TRAFFIC);

				if (PrlEvtPrm_GetBuffer(hPrm.get_handle(), &net_stat_buf, &len) == 0) {

					for (unsigned int i = 0; i < PRL_TC_CLASS_MAX; i++)
						fprintf(stdout, "\t%20s %2d %20llu %10u %20llu %10u\n", name_buff, i,
								net_stat_buf.incoming[i], net_stat_buf.incoming_pkt[i],
								net_stat_buf.outgoing[i], net_stat_buf.outgoing_pkt[i]);
				}
			}
		} else {
			ret = PrlEvtPrm_ToString(hPrm.get_handle(), val_buff, &len);
			if (PRL_FAILED(ret))
				return prl_err(ret, "PrlEvtPrm_ToString returned the following error: %s",
						get_error_str(ret).c_str());

			fprintf(stdout, "\t%s:\t%s\n", name_buff, val_buff);
		}

	}

	return PRL_ERR_SUCCESS;
}
示例#11
0
文件: PrlStat.cpp 项目: OpenVZ/prlctl
int PrlSrv::print_statistics(const CmdParamData &param, PrlVm *vm)
{
	PRL_RESULT ret;
	std::string err;

	if (param.list_all && !vm) {
		ret = update_vm_list(param.vmtype);
		if (PRL_FAILED(ret))
			return ret;
	}

	if (!param.statistics.loop)
		s_evt = new CEventSyncObject();

	const PrlHook *hHook = get_cleanup_ctx().register_hook(call_exit, NULL);

	if (param.action == SrvPerfStatsAction) {
		ret = PrlSrv_RegEventHandler(get_handle(), &perfstats_srv_callback, (void*)&param);
		if (PRL_FAILED(ret))
			return prl_err(ret, "PrlSrv_RegEventHandler returned the following error: %s",
					get_error_str(ret).c_str());
		PrlHandle hJob(PrlSrv_SubscribeToPerfStats(get_handle(), param.statistics.filter.c_str()));
		if (PRL_FAILED(get_job_retcode_predefined(hJob.get_handle(), err)))
			return prl_err(ret, "PrlSrv_SubscribeToPerfStats returned the following error: %s", err.c_str());
	}

	if (param.action == VmPerfStatsAction || param.list_all) {
		for (PrlVmList::iterator it = m_VmList.begin(), end = m_VmList.end(); it != end; ++it) {
			if (!param.list_all && (*it) != vm)
				continue;

			ret = PrlVm_RegEventHandler((*it)->get_handle(), &perfstats_vm_callback, (void*)&param);
			if (PRL_FAILED(ret))
				return prl_err(ret, "PrlVm_RegEventHandler returned the following error: %s",
						get_error_str(ret).c_str());
			PrlHandle hJob(PrlVm_SubscribeToPerfStats((*it)->get_handle(), param.statistics.filter.c_str()));
			if (PRL_FAILED(get_job_retcode_predefined(hJob.get_handle(), err)))
				return prl_err(ret, "PrlVm_SubscribeToPerfStats returned the following error: %s", err.c_str());
			if (s_evt) {
				s_evt->Wait(10000);
				s_evt->Reset();
				PrlVm_UnregEventHandler((*it)->get_handle(), &perfstats_vm_callback, (void*)&param);
				PrlHandle j(PrlVm_UnsubscribeFromPerfStats((*it)->get_handle()));
				get_job_retcode_predefined(j.get_handle(), err);
			}
		}
	}

	if (param.statistics.loop) {
		int ch = 0 ;
		while (ch!=0x0A && ch!=0x0D && ch!=0x03) {
			ch = _getch();
		}
		fprintf(stdout, "\n");
	}

	get_cleanup_ctx().unregister_hook(hHook);

	if (param.action == SrvPerfStatsAction)
		PrlSrv_UnregEventHandler(get_handle(), &perfstats_srv_callback, NULL);

	return 0;
}
示例#12
0
static int sdkTest_BtTestManual2(char *pasOutInfo, char const *pTitle) {
    char *temp = NULL, *temp1 = NULL;
    char rslt[256];
    int ret, i;
    int key;
    char *szAll = "1.������Ϣ\r2.����״̬\r3.������豸��Ϣ\r4.ƥ���豸��Ϣ\r5.ɾ��ƥ���豸ϵ��Ϣ";
    char connectInfo[64] = {0};

    ret = sdkBtGetStatus();
    memset(connectInfo, 0, sizeof(connectInfo));
    if (ret == SDK_BT_STATUS_WAITING || ret == SDK_BT_STATUS_WAITING)
        sprintf(connectInfo, "�豸�������޷�ִ��:");

    temp = (char *) sdkGetMem(BUF_LEN);
    if (temp == NULL) {
        Assert(0);
        return -1;
    }
    temp1 = (char *) sdkGetMem(BUF_LEN);
    if (temp1 == NULL) {
        Assert(0);
        sdkFreeMem(temp);
        return -1;
    }

    memset(temp, 0, BUF_LEN);
    memset(temp1, 0, BUF_LEN);

    for (; ;) {
        memset(temp, 0, BUF_LEN);
        key = sdkDispMsgBox("��ѡ�����ģ��", szAll, 0, SDK_KEY_MASK_ALL);

        switch (key) {
            case SDK_KEY_1: {
                memset(temp, 0, BUF_LEN);
                memset(temp1, 0, BUF_LEN);
                memset(rslt, 0, sizeof(rslt));
                ret = sdkBtGetVersion(temp, BUF_LEN);
                if (ret == SDK_OK) {
                    ret = sdkBtGetMVersion(temp1, BUF_LEN);
                    if (ret == SDK_OK) {
                        sprintf(rslt, "����汾=%s\r�̼��汾=%s\n", temp, temp1);
                    }
                    else {
                        get_error_str(rslt, ret, "sdkBtGetMVersion");
                    }

                    memset(temp, 0, BUF_LEN);
                    memset(temp1, 0, BUF_LEN);

                    ret = sdkBtGetName(temp, BUF_LEN);
                    if (ret == SDK_OK) {
                        sprintf(temp1, "Name=%s, ", temp);
                        strcat(rslt, temp1);

                        memset(temp, 0, BUF_LEN);
                        memset(temp1, 0, BUF_LEN);

                        ret = sdkBtGetPin(temp, BUF_LEN);
                        if (ret == SDK_OK) {
                            sprintf(temp1, "Pin=%s\r", temp);
                            strcat(rslt, temp1);

                            memset(temp, 0, BUF_LEN);
                            memset(temp1, 0, BUF_LEN);

                            ret = sdkBtGetMacAddr(temp, BUF_LEN);
                            if (ret == SDK_OK) {
                                sprintf(temp1, "MAC:  %2x:%2x:%2x:%2x:%2x:%2x\r", temp[0], temp[1],
                                        temp[2], temp[3], temp[4], temp[5]);
                            }
                            else {
                                sprintf(temp1, "%ssdkBtGetMacAddr\rfailed, ret=%d\r", connectInfo,
                                        ret);
                            }
                            strcat(rslt, temp1);
                        }
                        else {
                            memset(temp1, 0, BUF_LEN);
                            sprintf(temp1, "%ssdkBtGetPin\rfailed, ret=%d\r", connectInfo, ret);
                            strcat(rslt, temp1);
                        }
                    }
                    else {
                        sprintf(temp1, "%ssdkBtGetName\rfailed=%d\r", connectInfo, ret);
                        strcat(rslt, temp1);
                    }
                }
                else {
                    sprintf(rslt, "sdkBtGetVersion failed=%d\r", ret);
                }

                sdkDispMsgBox("������Ϣ", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_2: {
//            memset(temp, 0, BUF_LEN);
//            memset(temp1, 0, BUF_LEN);
                memset(rslt, 0, sizeof(rslt));

                ret = sdkBtGetStatus();
                if (ret == SDK_BT_STATUS_IDLE)
                    sprintf(rslt, "�豸δ����");
                else if (ret == SDK_BT_STATUS_WAITING || ret == SDK_BT_STATUS_WAITING)
                    sprintf(rslt, "�豸��������");
                else
                    sprintf(rslt, "��ȡ�豸״̬ʧ��");

                sdkDispMsgBox("����״̬", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_3: {
                SDK_BT_REMOTE_INFO stRemote;
                unsigned char *p;

                memset(&stRemote, 0, sizeof(SDK_BT_REMOTE_INFO));
                memset(rslt, 0, sizeof(rslt));
                ret = sdkBtGetRemoteInfo(&stRemote);
                if (ret == SDK_OK) {
                    p = stRemote.m_addr;
                    sprintf(rslt, "Զ���豸��Ϣrssi=%d,\r addr=%2x:%2x:%2x:%2x:%2x:%2x\n",
                            stRemote.m_rssi, *p,
                            *(p + 1), *(p + 2), *(p + 3), *(p + 4), *(p + 5));
                }
                else {
                    sprintf(rslt, "%s��ȡԶ���豸��Ϣ\rʧ��=%d\n", connectInfo, ret);
                }
                sdkDispMsgBox("Զ���豸��Ϣ", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_4: {
                SDK_BT_PAIR_INFO stPairInfo;
                unsigned char *p;

                memset(&stPairInfo, 0, sizeof(SDK_BT_PAIR_INFO));
                memset(rslt, 0, sizeof(rslt));
                memset(temp, 0, BUF_LEN);

                ret = sdkBtGetPairDevInfo(&stPairInfo);
                if (ret == SDK_OK) {
                    Trace("bt_test", "PairInfo num=%d\n", stPairInfo.m_num);
#if 1
                    sprintf(rslt, "���%d���豸��Ϣ:\r", stPairInfo.m_num);
                    for (i = 0; i < stPairInfo.m_num; i++) {
                        p = stPairInfo.m_addr[i];
                        sprintf(temp, "%d:%s\rdev:%2X:%2X:%2X:%2X:%2X:%2X\r", i,
                                stPairInfo.m_name[i], p[0], p[1], p[2], p[3], p[4], p[5]);
                        strcat(rslt, temp);
                    }
#else
                    sprintf(rslt, "���%d���豸:\raddr:%2X:%2X:%2X:%2X:%2X:%2X\r", stPairInfo.m_num, stPairInfo.m_addr[0][0],
                        stPairInfo.m_addr[0][1], stPairInfo.m_addr[0][2], stPairInfo.m_addr[0][3], stPairInfo.m_addr[0][4],
                        stPairInfo.m_addr[0][5]);
#endif
                }
                else {
                    sprintf(rslt, "%ssdkBtGetPairDevInfo/rfailed=%d\r", connectInfo, ret);
                }

                Trace("bt_test", rslt);
                sdkDispMsgBox("�����Ϣ", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_5: {
                u8 iidx;
                SDK_BT_PAIR_INFO stPairInfo;
                memset(&stPairInfo, 0, sizeof(SDK_BT_PAIR_INFO));
                memset(temp, 0, BUF_LEN);
                memset(rslt, 0, sizeof(rslt));

                sdkBtGetPairDevInfo(&stPairInfo);
                sprintf(temp, "����%d���豸����������Ҫɾ�����豸��:", stPairInfo.m_num);
                iidx = sdkTestInputU8(pTitle, temp);
                Trace("zjp", "sdkBtDelPairDevInfo = %d\r\n", iidx);
                ret = sdkBtDelPairDevInfo(iidx);
                if (ret == SDK_OK)
                    sprintf(rslt, "��ɾ��%d�����Ϣ\n", iidx);
                else
                    sprintf(rslt, "%sɾ��%d�����Ϣ\rʧ��=%d\r", connectInfo, iidx, ret);

                sdkDispMsgBox("ɾ�������Ϣ", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_ESC:
            case SDK_KEY_CLEAR:
                goto end;
            default:
                break;
        }
    }

    end:
    if (temp) sdkFreeMem(temp);
    if (temp1) sdkFreeMem(temp1);

    return SDK_OK;
}
示例#13
0
// Check if the error is caused by an incoming ICMP error. If so, then deliver
// the ICMP error to the transaction manager.
//
// err - error returned by sendto
// dst_addr - destination IP address of packet that failed to be sent
// dst_port - destination port of packet that failed to be sent
//
// Returns true if the packet that failed to be sent, should still be sent.
// Returns false if the packet that failed to be sent, should be discarded.
static bool handle_socket_err(int err, unsigned long dst_addr, unsigned short dst_port) {
	string log_msg;

	// Check if an ICMP error has been received
	t_icmp_msg icmp;
	if (sip_socket->get_icmp(icmp)) {
		log_msg = "Received ICMP from: ";
		log_msg += h_ip2str(icmp.icmp_src_ipaddr);
		log_msg += "\nICMP type: ";
		log_msg += int2str(icmp.type);
		log_msg += "\nICMP code: ";
		log_msg += int2str(icmp.code);
		log_msg += "\nDestination of packet causing ICMP: ";
		log_msg += h_ip2str(icmp.ipaddr);
		log_msg += ":";
		log_msg += int2str(icmp.port);
		log_msg += "\nSocket error: ";
		log_msg += int2str(err);
		log_msg += " ";
		log_msg += get_error_str(err);
		log_file->write_report(log_msg, "::hanlde_socket_err", LOG_NORMAL);

		evq_trans_mgr->push_icmp(icmp);
		
		num_non_icmp_errors = 0;
		
		// If the ICMP error comes from the same destination as the
		// destination of the packet that failed to be sent, then the
		// packet should be discarded as it can most likely not be
		// delivered and would cause an infinite loop of ICMP errors
		// otherwise.
		if (icmp.ipaddr == dst_addr && icmp.port == dst_port) {
			return false;
		}
	} else {
		// Even if an ICMP message is received this code can get executed.
		// Sometimes the error is already present on the socket, but the ICMP
		// message is not yet queued.
		log_msg = "Failed to send to SIP UDP socket.\n";
		log_msg += "Error code: ";
		log_msg += int2str(err);
		log_msg += "\n";
		log_msg += get_error_str(err);
		log_file->write_report(log_msg, "::handle_socket_err");
		
		num_non_icmp_errors++;
		
		/*
		 * non-ICMP errors occur when a destination on the same
		 * subnet cannot be reached. So this code seems to be
		 * harmful.
		if (num_non_icmp_errors > 100) {
			log_msg = "Excessive number of socket errors.";
			log_file->write_report(log_msg, "::handle_socket_err", 
				LOG_NORMAL, LOG_CRITICAL);
			log_msg = TRANSLATE("Excessive number of socket errors.");
			ui->cb_show_msg(log_msg, MSG_CRITICAL);
			exit(1);
		}
		*/
	}
	
	return true;
}
示例#14
0
void *tcp_sender_loop(void *arg) {
	string log_msg;
	list<t_connection *> writable_connections;
	
	while(true) {
		writable_connections.clear();
		writable_connections = connection_table->select_write(NULL);
		
		if (writable_connections.empty()) {
			// Another thread cancelled the select command.
			// Stop listening.
			break;
		}
		
		// NOTE: The connection table is now locked.
		
		for (list<t_connection *>::iterator it = writable_connections.begin();
			it != writable_connections.end(); ++it)
		{
			try {
				(*it)->write();
			} catch (int err) {
				if (err == EAGAIN || err == EWOULDBLOCK || err == EINTR) {
					continue;
				}
				
				unsigned long remote_addr;
				unsigned short remote_port;
			
				(*it)->get_remote_address(remote_addr, remote_port);
				
				log_msg = "Got error on socket to ";
				log_msg += h_ip2str(remote_addr);
				log_msg += ":";
				log_msg += int2str(remote_port);
				log_msg += " - ";
				log_msg += get_error_str(err);
				log_file->write_report(log_msg, "::tcp_sender_loop", LOG_SIP, LOG_WARNING);
				
				// Connection is broken. 
				// Signal the transaction layer that the connection is broken for
				// all associated registered URI's.
				const list<t_url> &uris = (*it)->get_registered_uri_set();
				for (list<t_url>::const_iterator it_uri = uris.begin(); 
				     it_uri != uris.end(); ++it_uri)
				{
					evq_trans_layer->push_broken_connection(*it_uri);
				}
				
				// Remove the broken connection.
				connection_table->remove_connection(*it);
				MEMMAN_DELETE(*it);
				delete *it;
				
				continue;
			}
		}
		
		connection_table->unlock();
	}
	
	log_file->write_report("TCP sender terminated.", "::tcp_sender_loop");
	return NULL;
}
示例#15
0
void exec_cmd(t_socket_local &sock_client) {
	t_cmd_code opcode;
	bool immediate;
	int len;
	string log_msg;

	try {
		if (sock_client.read(&opcode, sizeof(opcode)) != sizeof(opcode)) {
			log_file->write_report("Failed to read opcode from socket.",
				"cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
			return;
		}
		
		if (sock_client.read(&immediate, sizeof(immediate)) != sizeof(immediate)) {
			log_file->write_report("Failed to read immediate mode from socket.",
				"cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
			return;
		}
	
		if (sock_client.read(&len, sizeof(len)) != sizeof(len)) {
			log_file->write_report("Failed to read length from socket.",
				"cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
			return;
		}
		
		char args[len];
		
		if (sock_client.read(args, len) != len) {
			log_file->write_report("Failed to read arguments from socket.",
				"cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
			return;
		}
		
		log_file->write_header("cmdsocket::exec_cmd", LOG_NORMAL, LOG_DEBUG);
		log_file->write_raw("External command received:\n");
		log_file->write_raw("Opcode: ");
		log_file->write_raw(cmd_code2str(opcode));
		log_file->write_raw("\nImmediate: ");
		log_file->write_raw(bool2yesno(immediate));
		log_file->write_raw("\nArguments: ");
		log_file->write_raw(args);
		log_file->write_endl();
		log_file->write_footer();
		
		switch (opcode) {
		case CMD_CALL:
			ui->cmd_call(args, immediate);
			break;
		case CMD_CLI:
			ui->cmd_cli(args, immediate);
			break;
		case CMD_SHOW:
			ui->cmd_show();
			break;
		case CMD_HIDE:
			ui->cmd_hide();
			break;
		default:
			// Discard unknown commands
			log_file->write_header("cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
			log_file->write_raw("Unknown external command received:\n");
			log_file->write_raw("Opcode: ");
			log_file->write_raw(cmd_code2str(opcode));
			log_file->write_raw("\nImmediate: ");
			log_file->write_raw(bool2yesno(immediate));
			log_file->write_raw("\nArguments: ");
			log_file->write_raw(args);
			log_file->write_endl();
			log_file->write_footer();
			break;
		}
	}
	catch (int e) {
		log_msg = "Failed to read from socket.\n";
		log_msg += get_error_str(e);
		log_msg += "\n";
		log_file->write_report(log_msg, "cmdsocket::exec_cmd", LOG_NORMAL, LOG_WARNING);
	}
}
示例#16
0
/*######################## popup_error_history() ########################*/
void
popup_error_history(int x_root, int y_root, int host_no)
{
   if (error_shell != NULL)
   {
      destroy_error_history();
   }

   if (fsa[host_no].error_history[0] != 0)
   {
      Widget   error_label,
               form;
      XmString x_string;
      int      display_height,
               display_width,
               error_list_length,
               i,
               length,
               lines,
               max_lines,
               max_length,
               over_hang,
               str_length;
      char     *error_list;

      /* Lets determine how many lines we are able to display. */
      display_height = DisplayHeight(display, DefaultScreen(display));
      max_lines = display_height / glyph_height;
   
      error_list_length = ERROR_HISTORY_LENGTH *
                          (5 + 1 + MAX_ERROR_STR_LENGTH + 1);
      if ((error_list = malloc(error_list_length)) == NULL)
      {
         (void)fprintf(stderr, "malloc() error : %s (%s %d)\n",
                       strerror(errno), __FILE__, __LINE__);
         exit(INCORRECT);
      }
      length = max_length = lines = 0;

      str_length = sprintf(error_list + length, "[%d] %s\n",
                           (int)fsa[host_no].error_history[0],
                           get_error_str(fsa[host_no].error_history[0]));
      if (str_length > max_length)
      {
         max_length = str_length;
      }
      length += str_length;
      lines++;
      for (i = 1; i < ERROR_HISTORY_LENGTH; i++)
      {
         if ((fsa[host_no].error_history[i] == 0) || (lines >= max_lines))
         {
            i = ERROR_HISTORY_LENGTH;
         }
         else
         {
            str_length = sprintf(error_list + length, "[%d] %s\n",
                                 (int)fsa[host_no].error_history[i],
                                 get_error_str(fsa[host_no].error_history[i]));
            if (str_length > max_length)
            {
               max_length = str_length;
            }
            length += str_length;
            lines++;
         }
      }

      error_shell = XtVaCreatePopupShell("error_history_shell",
                                      topLevelShellWidgetClass, appshell,
                                      XtNoverrideRedirect,      True,
                                      XtNallowShellResize,      True,
                                      XtNmappedWhenManaged,     False,
                                      XtNsensitive,             True,
                                      XtNwidth,                 1,
                                      XtNheight,                1,
                                      XtNborderWidth,           0,
                                      NULL);
      XtManageChild(error_shell);
      XtAddEventHandler(error_shell, ButtonPressMask | Button1MotionMask,
                        False, (XtEventHandler)eh_input, NULL);
      form = XtVaCreateWidget("error_box",
                              xmFormWidgetClass, error_shell, NULL);
      XtManageChild(form);

      display_width = DisplayWidth(display, DefaultScreen(display));
      over_hang = display_width - (x_root + (max_length * glyph_width));
      if (over_hang < 0)
      {
         x_root += over_hang;
      }
      over_hang = display_height - (y_root + (lines * glyph_height));
      if (over_hang < 0)
      {
         y_root += over_hang;
      }
      XMoveResizeWindow(display, XtWindow(error_shell),
                        x_root, y_root, max_length * glyph_width, lines * glyph_height);

      error_list[length - 1] = '\0';
      x_string = XmStringCreateLocalized(error_list);
      error_label = XtVaCreateWidget("error_label",
                                  xmLabelWidgetClass, form,
                                  XmNlabelString,     x_string,
                                  XtNbackground,      color_pool[WHITE],
                                  XtNforeground,      color_pool[BLACK],
                                  NULL);
      XtManageChild(error_label);
      XmStringFree(x_string);
      XtAddEventHandler(error_label, ButtonPressMask|LeaveWindowMask, False,
                        (XtEventHandler)destroy_error_history, NULL);
      XtPopup(error_shell, XtGrabNone);
      XRaiseWindow(display, XtWindow(error_shell));
      free(error_list);
   }
   else
   {
      destroy_error_history();
   }

   return;
}
示例#17
0
t_media_stun_trans::t_media_stun_trans(t_user *user, StunMessage *r,
			 unsigned short _tuid, const list<t_ip_port> &dst, 
			 unsigned short src_port) :
		t_stun_transaction(user, r, _tuid, dst)
{
	thr_listen = NULL;
	
	try {
		sock = new t_socket_udp(src_port);
		MEMMAN_NEW(sock);
		sock->connect(destinations.front().ipaddr, destinations.front().port);
	} catch (int err) {
		string msg("Failed to create a UDP socket (STUN) on port ");
		msg += int2str(src_port);
		msg += "\n";
		msg += get_error_str(err);
		log_file->write_report(msg, "t_media_stun_trans::t_media_stun_trans", LOG_NORMAL, 
			LOG_CRITICAL);
		delete sock;
		sock = NULL;
		
		StunMessage *resp;
		resp = stunBuildError(*request, 500, "Could not create socket");

		evq_trans_layer->push_stun_response(resp, tuid, id);
		MEMMAN_DELETE(resp);
		delete resp;
		
		return;
	}
	
	// Send STUN request
	StunAtrString stun_pass;
	stun_pass.sizeValue = 0;
	char m[STUN_MAX_MESSAGE_SIZE];
	int msg_size = stunEncodeMessage(*r, m, STUN_MAX_MESSAGE_SIZE, stun_pass, false);
	
	try {
		sock->send(m, msg_size);
	} catch (int err) {
		string msg("Failed to send STUN request for media.\n");
		msg += get_error_str(err);
		log_file->write_report(msg, "::t_media_stun_trans::t_media_stun_trans",
			LOG_NORMAL, LOG_CRITICAL);

		StunMessage *resp;
		resp = stunBuildError(*request, 500, "Failed to send request");

		evq_trans_layer->push_stun_response(resp, tuid, id);
		MEMMAN_DELETE(resp);
		delete resp;
		
		return;
	}
	
	num_transmissions++;
	
	try {
		thr_listen = new t_thread(stun_listen_main, sock);
		MEMMAN_NEW(thr_listen);
	} catch (int) {
		log_file->write_report("Failed to create STUN listener thread.",
			"::t_media_stun_trans::t_media_stun_trans",
			LOG_NORMAL, LOG_CRITICAL);
		delete thr_listen;
		thr_listen = NULL;

		StunMessage *resp;
		resp = stunBuildError(*request, 500, "Failed to create STUN listen thread");

		evq_trans_layer->push_stun_response(resp, tuid, id);
		MEMMAN_DELETE(resp);
		delete resp;		
		
		return;
	}
	
	start_timer_req_timeout();
	state = TS_PROCEEDING;
}
示例#18
0
static int sdkTest_BtTestManual(char *pasOutInfo, char const *pTitle) {
    static int iopen = 0;
    static int ivisable = 0;
    static char szMac[6];
    s32 ret;
//    u32 timerid = 0;
    char *temp = NULL, *temp1 = NULL;
    char rslt[256];
//    bool bwrite=false;
//    int nCount=0;
    int key, key2;


    char *szopen[] = {"1.�������豸", "1.�ر������豸"};
    char *szvisable[] = {"3.�����豸�ɼ�", "3.�����豸���ɼ�"};
    char *szAll = "%s\r2.�����������ƺ�����\r%s\r4.��������\r5.��������\r6.�Ͽ�����\r7.����1023���ַ�\r0.����������Ϣ";
    temp = (char *) sdkGetMem(BUF_LEN);
    if (temp == NULL) {
        Assert(0);
        return -1;
    }
    temp1 = (char *) sdkGetMem(BUF_LEN);
    if (temp1 == NULL) {
        Assert(0);
        sdkFreeMem(temp);
        return -1;
    }
    memset(temp, 0, BUF_LEN);
    memset(temp1, 0, BUF_LEN);

    for (; ;) {
        memset(temp, 0, BUF_LEN);
        sprintf(temp, szAll, szopen[iopen], szvisable[ivisable]);
        key = sdkDispMsgBox("��ѡ�����ģ��", temp, 0, SDK_KEY_MASK_ALL);

        switch (key) {
            case SDK_KEY_1: {
                memset(rslt, 0, sizeof(rslt));
                if (iopen == 0) {
                    ret = sdkBtOpen();
                    if (ret != SDK_OK)
                        sprintf(rslt, "sdkBtOpen failed=%d\n", ret);
                    else {
                        iopen = 1;
                        sprintf(rslt, "�����豸�Ѵ�\n");

                        memset(szMac, 0, sizeof(szMac));
                        sdkBtGetMacAddr(szMac, sizeof(szMac));
                    }
                }
                else {
                    ret = sdkBtClose();
                    if (ret == SDK_OK) {
                        iopen = 0;
                        if (ivisable == 1)
                            ivisable = 0;
                        sprintf(rslt, "�����豸�ѹر�\n");
                    }
                    else {
                        sprintf(rslt, "sdkBtClose failed=%d\n", ret);
                    }
                }

                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_2: {
                memset(temp, 0, BUF_LEN);
                memset(rslt, 0, sizeof(rslt));

                sdkTestPresetInputASC(temp, pTitle, "�豸����:", "bt123", 2, 64);
                ret = sdkBtSetName(temp);
                if (ret == SDK_OK) {
                    memset(temp, 0, BUF_LEN);
                    sdkTestPresetInputASC(temp, pTitle, "����PIN:", "123456", 6, 6);
                    ret = sdkBtSetPin(temp);
                    if (ret == SDK_OK) {
                        sprintf(rslt, "�豸��Ϣ���óɹ�\n");
                    }
                    else {
                        get_error_str(rslt, ret, "sdkBtSetPin");
                    }
                }
                else {
                    sprintf(rslt, "sdkBtSetName failed=%d\n", ret);
                }
                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_3: {
                memset(rslt, 0, sizeof(rslt));
                if (ivisable == 0) {
                    ret = sdkBtSetDiscoverable(true);
                    if (ret == SDK_OK) {
                        ivisable = 1;
                        sprintf(rslt, "�����������豸�ɼ�");
                    }
                    else {
                        get_error_str(rslt, ret, "sdkBtSetDiscoverable");
                    }
                }
                else {
                    ret = sdkBtSetDiscoverable(false);
                    if (ret == SDK_OK) {
                        ivisable = 0;
                        sprintf(rslt, "�����������豸���ɼ�");
                    }
                    else {
                        get_error_str(rslt, ret, "sdkBtSetDiscoverable");
                    }

                }
                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_4: {
                memset(rslt, 0, sizeof(rslt));

                for (; ;) {
                    ret = sdkBtGetStatus();
                    switch (ret) {
                        case SDK_BT_STATUS_IDLE:
                            sprintf(rslt, "�豸��δ����", temp);
                            break;
                        case SDK_BT_STATUS_WORKING:
                        case SDK_BT_STATUS_WAITING:
                            sprintf(rslt, "�ȴ���������", temp);
                            break;
                        case SDK_ERR:
                        case SDK_EIO: {
                            memset(rslt, 0, sizeof(rslt));
                            sprintf(rslt, "sdkBtGetStatus failed=%d\n", ret);
                            strcpy(pasOutInfo, rslt);
                            goto end;
                        }
                        default:
                            break;
                    }

                    sdkDispClearScreen();
                    sdkDispAt(0, 0, rslt);

                    memset(temp1, 0, BUF_LEN);
                    memset(rslt, 0, sizeof(rslt));
                    ret = sdkBtRead(temp1, BUF_LEN, 1000);
                    if (ret < 0) {
                        get_error_str(rslt, ret, "sdkBtRead");
                    }
                    else if (ret > 0) {
                        TraceHex("bt_test", "receive data", temp1, ret);
                        sprintf(rslt, "��������len=%d, %s\r\n", ret, temp1);
                        sdkBtWrite(temp1, ret, 0);
                    }

                    if (strlen(rslt) > 0) {
                        sdkDispClearScreen();
                        sdkDispLabel(SDK_DISP_LINE2, rslt, SDK_DISP_LEFT_DEFAULT);
                    }
                    key2 = sdkKbWaitKey(SDK_KEY_MASK_ALL, 1000);
                    if (key2 == SDK_KEY_CLEAR || key2 == SDK_KEY_ESC) {
                        break;
                    }
                }
                break;
            }
            case SDK_KEY_5: {
                memset(rslt, 0, sizeof(rslt));
                memset(temp1, 0, BUF_LEN);

                sdkTestPresetInputASC(temp1, pTitle, "�����뷢�͵�����", "hello", 1, 127);
                ret = sdkBtWrite(temp1, strlen(temp1), 0);
                if (ret > 0) {
                    sdkDispClearScreen();
                    sprintf(rslt, "��������=%s, len=%d\n", temp1, strlen(temp1));
                }
                else {
                    get_error_str(rslt, ret, "sdkBtWrite");
                }

                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                break;
            }
            case SDK_KEY_6: {
                SDK_BT_REMOTE_INFO stRemote;
                memset(rslt, 0, sizeof(rslt));
                memset(&stRemote, 0, sizeof(SDK_BT_REMOTE_INFO));
#if 0
                ret = sdkBtGetRemoteInfo(&stRemote);
                if (ret == SDK_OK)
                {
                    ret = sdkBtDisconnect(stRemote.m_addr);
                    if(ret == SDK_OK)
                    {
                        sprintf(rslt, "�ѶϿ���%s������\n", stRemote.m_addr);
                    }
                    else
                    {
                        sprintf(rslt, "����sdkBtDisconnect failed, ret=%s\n", ret);
                    }
                }
                else
                {
                    sprintf(rslt, "����sdkBtGetRemoteInfoʧ�ܣ����ܻ�ȡ�����豸��MAC��ַ\n");
                }
#else
                ret = sdkBtDisconnect(szMac);
                if (ret == SDK_OK) {
                    sprintf(rslt, "�ѶϿ�����\n");
                    if (ivisable == 1)
                        ivisable = 0;
                }
                else {
                    get_error_str(rslt, ret, "sdkBtDisconnect");
                }
#endif
                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);

                break;
            }
            case SDK_KEY_7: {
                int ret;
                char *tmp_big = sdkGetMem(1024);
                if (tmp_big == NULL)
                    break;

                memset(tmp_big, 0x61, 1023);
                tmp_big[1023] = '\0';
                ret = sdkBtWrite(tmp_big, 1023, 0);
                if (ret < 0) {
                    switch (ret) {
                        case SDK_ERR:
                            sprintf(rslt, "sdkBtWrite ����ʧ��\n");
                            break;
                        case SDK_EIO:
                            sprintf(rslt, "sdkBtWrite ����: �豸δ��\n");
                            break;
                        case SDK_PARA_ERR:
                            sprintf(rslt, "sdkBtWrite ����: ��������\n");
                            break;
                    }
                }
                else {
                    sprintf(rslt, "sdkBtWrite ����: ���ͳɹ���ret=%d\n", ret);
                }

                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                sdkFreeMem(tmp_big);
                break;
            }
            case SDK_KEY_8: {
                int ret;
                char *tmp_big = sdkGetMem(3072);
                if (tmp_big == NULL)
                    break;

                memset(tmp_big, 0, 3072);
                ret = sdkBtRead(tmp_big, 3071, 30000);
                if (ret < 0) {
                    switch (ret) {
                        case SDK_ERR:
                            sprintf(rslt, "sdkBtRead ����ʧ��\n");
                            break;
                        case SDK_EIO:
                            sprintf(rslt, "sdkBtRead ����: �豸δ��\n");
                            break;
                        case SDK_PARA_ERR:
                            sprintf(rslt, "sdkBtRead ����: ��������\n");
                            break;
                        case SDK_TIME_OUT:
                            sprintf(rslt, "sdkBtRead ����: ��ʱ����\n");
                            break;
                    }
                }
                else {
                    sprintf(rslt, "sdkBtRead ����: ���ճɹ���ret=%d\n", ret);
                }

                sdkDispMsgBox("��������", rslt, 0, SDK_KEY_MASK_ALL);
                sdkFreeMem(tmp_big);
                break;
            }
            case SDK_KEY_9: {
                int ret;
                sdkDispMsgBox("��������", "�����������͹���", 0, SDK_KEY_MASK_ALL);
                sdkSysEnterIdle(1, 1);

                memset(rslt, 0, sizeof(rslt));
                for (; ;) {
                    ret = sdkBtGetStatus();
                    switch (ret) {
                        case SDK_BT_STATUS_IDLE:
                            sprintf(rslt, "�豸��δ����", temp);
                            break;
                        case SDK_BT_STATUS_WORKING:
                        case SDK_BT_STATUS_WAITING:
                            sprintf(rslt, "�ȴ���������", temp);
                            break;
                        case SDK_ERR:
                        case SDK_EIO: {
                            memset(rslt, 0, sizeof(rslt));
                            sprintf(rslt, "sdkBtGetStatus failed=%d\n", ret);
                            strcpy(pasOutInfo, rslt);
                            goto end;
                        }
                        default:
                            break;
                    }

                    sdkDispClearScreen();
                    sdkDispAt(0, 0, rslt);

                    memset(temp1, 0, BUF_LEN);
                    memset(rslt, 0, sizeof(rslt));
                    ret = sdkBtRead(temp1, BUF_LEN, 1000);
                    if (ret < 0) {
                        get_error_str(rslt, ret, "sdkBtRead");
                    }
                    else if (ret > 0) {
                        TraceHex("bt_test", "receive data", temp1, ret);
                        sprintf(rslt, "��������len=%d, %s\r\n", ret, temp1);
                        sdkBtWrite(temp1, ret, 0);
                    }

                    if (strlen(rslt) > 0) {
                        sdkDispClearScreen();
                        sdkDispLabel(SDK_DISP_LINE2, rslt, SDK_DISP_LEFT_DEFAULT);
                    }
                    key2 = sdkKbWaitKey(SDK_KEY_MASK_ALL, 1000);
                    if (key2 == SDK_KEY_CLEAR || key2 == SDK_KEY_ESC) {
                        break;
                    }
                }
                break;
            }
            case SDK_KEY_0:
                sdkTest_BtTestManual2(pasOutInfo, pTitle);
                break;
            case SDK_KEY_ESC:
            case SDK_KEY_CLEAR:
                goto end;
            default:
                break;
        }
    }

    end:
    memset(temp, 0, BUF_LEN);
//    sdkBtGetMacAddr(temp, BUF_LEN);
//    sdkBtDisconnect(temp);
    if (iopen) {
        sdkBtClose();
    }
    iopen = 0;
    ivisable = 0;

    if (temp) sdkFreeMem(temp);
    if (temp1) sdkFreeMem(temp1);

    return SDK_OK;
}