⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bttest.c

📁 bluetooth 驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * bttest.c -- Open BT Test application * * Copyright (C) 2000, 2001  Axis Communications AB * * Author: Mattias Agren <mattias.agren@axis.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * Exceptionally, Axis Communications AB grants discretionary and * conditional permissions for additional use of the text contained * in the company's release of the AXIS OpenBT Stack under the * provisions set forth hereunder. * * Provided that, if you use the AXIS OpenBT Stack with other files, * that do not implement functionality as specified in the Bluetooth * System specification, to produce an executable, this does not by * itself cause the resulting executable to be covered by the GNU * General Public License. Your use of that executable is in no way * restricted on account of using the AXIS OpenBT Stack code with it. * * This exception does not however invalidate any other reasons why * the executable file might be covered by the provisions of the GNU * General Public License. * * $Id: bttest.c,v 1.23 2001/10/16 16:26:43 anderstj Exp $ * */#include <sys/time.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/wait.h>#include <fcntl.h>#include <time.h>#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <stdlib.h>#include <string.h>#include <syslog.h>#include <errno.h>#include <stdarg.h>#include <signal.h>#if defined(HAVE_READLINE_READLINE)#include <readline/readline.h>#include <readline/history.h>#elif defined(HAVE_READLINE)#include <readline.h>#include <history.h>#endif#include "btd.h"#include "bttest.h"#include "bt_if.h"#include "bt_misc.h"#include "bt_conf.h"#include "bt_vendor.h"#include "bt_errno.h"/* ============================================================== */#define BTD_HISTORY_FILE "/tmp/btd_history"char* menu[] ={  "\nMenu",  "------------------------",  "  inq <max nbr resp> <inq time>",  "  rf_conn <xx:xx:xx:xx:xx:xx> <srv ch> <line>",  "  rf_send <nbr bytes> <nbr repeats> <line>",   "  rf_disc <line>",  "  rf_wait <line>", /* waits for a connection on that line */  "  ping <xx:xx:xx:xx:xx:xx> <nbr bytes>",  "  getinfo <xx:xx:xx:xx:xx:xx> <type>",  "  setbd <xx:xx:xx:xx:xx:xx>", /* only ericsson HW */  "  readbd", /* read module bd address */  "  reset", /* reset board */  "  bt_wrscan <mode>",  "  force_ms <0/1>", /* force ms switch */  "  role_switch <xx:xx:xx:xx:xx:xx> <role> (0=master, 1=slave)",  "  stat ", /* similar to reading the /proc/bt */#ifdef ECS_TEST_FUNCTIONS  "  ecs_entertest <handle> (hex)",  "  ecs_testctrl <par1,par2,...,par9> (hex)",  "  ecs_txtest   <par1,par2,...,par11> (hex)",  "  ecs_testcon <xx:xx:xx:xx:xx:xx> (hex)",    "  enable_dut", /* enable device under test mode */#endif#ifdef CONFIG_BLUETOOTH_UNPLUG_TEST  "  upt <teststring>", /* e.g testcase 4.3 't 43' */#endif  "  quit",   "",  "--- Test commands ------",  "  sdp_conn  <xx:xx:xx:xx:xx:xx>",  "  tcs_conn  <xx:xx:xx:xx:xx:xx>",  "                               ",  "  test_conn  <xx:xx:xx:xx:xx:xx> <psm> <line>", /* l2cap test using PSM psm */  "  test_disc <psm>", /* disconnect the connection with psm=psm */  "  test_case_reject <xx:xx:xx:xx:xx:xx>",   "                               ",  "  bb_conn  <xx:xx:xx:xx:xx:xx>", /* connect only baseband */  "  bb_disc  <hci handle>", /* disconnect baseband */  "  lcid_disconnect <lcid>", /* Disconnects a connection with lcid = lcid */  "                               ",  "-------- Hotlist -------",  "  (Use !<num> to expand the bdaddr from the list in any command)",  "  hotlist_set <pos> <xx:xx:xx:xx:xx:xx>",  "  hotlist_show",   "",  NULL};static unsigned char hotlist[10][6];static int quit_bttest;#if !defined(HAVE_READLINE) && !defined(HAVE_READLINE_READLINE)static void read_history(char *hist_file_name);static void write_history(char *hist_file_name);static void add_history(char *command);static char *readline(char *promt);#endif voidshow_menu(void){  char** option;  option = menu;  while (*option)  {    printf("%s\n", *option);    option++;  }         }intmain(int argc, char **argv){  int bt_cfd, i , j, tmp;  FILE *hotlist_fd;  quit_bttest = 0;  /* Open BT ctrl device */    if ((bt_cfd = bt_openctrl()) < 0)  {    perror("Could not open BT control device");    exit(1);  }  /* First of all check that stack is running */  if (!bt_isinitiated(bt_cfd))  {    printf("Stack not initiated, exit\n");    exit(1);  }  if((hotlist_fd = fopen("/etc/.hotlist", "rb")))  {    for (i = 0; i < 10 ; i++)     {      for (j = 0 ; j < 6 ; j++)       {        hotlist[i][j] = fgetc(hotlist_fd);      }    }    fclose(hotlist_fd);  }  else  {    for (i = 0; i < 10 ; i++)     {      for (j = 0 ; j < 6 ; j++)       {        hotlist[i][j] = 0;      }    }  }    if(argc > 1)  {    for(i = 1 ; i < argc ; i++)    {      if((tmp = process_cmd(argv[i], bt_cfd)) < 0)      {	return -1;      }    }    return 0;  }        read_history(BTD_HISTORY_FILE);      show_menu();    while (1)  {    char *tmp_char, hotlist_entry;    char tmp_line[200];    char *line = (char*) readline("> ");    add_history(line);        if((tmp_char = strstr(line, "!")))    {      if(*(tmp_char + 1) >= '0' && *(tmp_char + 1) <= '9')      {        hotlist_entry = *(tmp_char + 1) - '0';        memcpy(&tmp_line[0], line, tmp_char - line);        sprintf(&tmp_line[tmp_char - line], "%02X:%02X:%02X:%02X:%02X:%02X%s\0",                 hotlist[hotlist_entry][0],                hotlist[hotlist_entry][1],                hotlist[hotlist_entry][2],                hotlist[hotlist_entry][3],                hotlist[hotlist_entry][4],                hotlist[hotlist_entry][5],                tmp_char + 2);        tmp = process_cmd(&tmp_line[0], bt_cfd);      }    }    else    {         tmp = process_cmd(line, bt_cfd);    }    if (quit_bttest == QUIT_BTD)    {      break;    }    free(line);  }  write_history(BTD_HISTORY_FILE);  exit(0);}intprocess_cmd(char *buf, int bt_cfd){  unsigned int i, con_id, tmp[10], repeat, line = 0, profile, srv_ch;  int retval = 0;  unsigned char bd[6];  if (!strncmp(buf, "quit", 4))  {    quit_bttest = QUIT_BTD;  }  else if (sscanf(buf, "rf_conn %x:%x:%x:%x:%x:%x %d %d",		  &tmp[0], &tmp[1], &tmp[2],		  &tmp[3], &tmp[4], &tmp[5],		  &tmp[6], &tmp[7]) == 8)  {    for (i = 0; i < 6; i++)    {      bd[i] = (unsigned char)tmp[i];    }        /* layer specific for rfcomm is 16 bits => | line | dlci | */        line = (unsigned short)(tmp[7]);    srv_ch = (unsigned short)(tmp[6]);    con_id = CREATE_RFCOMM_ID(line, srv_ch<<1);        retval = bt_connect(bt_cfd, bd, con_id);  }  else if (sscanf(buf, "bt_wrscan %d", &tmp[0]) == 1)  {    printf("Setting wr scan enable to %d\n", tmp[0]);    bt_write_scan_enable(bt_cfd, tmp[0]);  }  else if (sscanf(buf, "rf_disc %d", &line) == 1)  {    unsigned int con_id;    con_id = CREATE_RFCOMM_ID(line, 0 /* fixme -- don't care */);    retval = bt_disconnect(bt_cfd, con_id);  }  else if (sscanf(buf, "rf_wait %d", &line) == 1)  {    bt_waitconnection(bt_cfd, line);    printf("Connect on line %d\n", line);  }  else if (sscanf(buf, "inq %d %d", &tmp[0], &tmp[1]) == 2)  {    retval = bt_inquiry(bt_cfd, tmp[0], tmp[1]);  }  else if (sscanf(buf, "rf_send %d %d %d", &i, &repeat, &line) == 3)  {    int btfd;    char dev[20];    sprintf(dev, "/dev/ttyBT%d", line);    btfd = open(dev, O_RDWR | O_NOCTTY);    if (btfd > 0)      return bt_send(btfd, i, repeat);    else    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -