Exemplo n.º 1
0
void ubertooth_stop(struct libusb_device_handle *devh)
{
	/* make sure xfers are not active */
	if(rx_xfer != NULL)
		libusb_cancel_transfer(rx_xfer);
	if (devh != NULL) {
		cmd_stop(devh);
		libusb_release_interface(devh, 0);
	}
	libusb_close(devh);
	libusb_exit(NULL);

#if defined(USE_PCAP)
	if (h_pcap_bredr) {
		btbb_pcap_close(h_pcap_bredr);
		h_pcap_bredr = NULL;
	}
	if (h_pcap_le) {
		lell_pcap_close(h_pcap_le);
		h_pcap_le = NULL;
	}
#endif
	if (h_pcapng_bredr) {
		btbb_pcapng_close(h_pcapng_bredr);
		h_pcapng_bredr = NULL;
	}
	if (h_pcapng_le) {
		lell_pcapng_close(h_pcapng_le);
		h_pcapng_le = NULL;
	}
}
Exemplo n.º 2
0
/* Receive and process packets. For now, returning from
 * stream_rx_usb() means that UAP and clocks have been found, and that
 * hopping should be started. A more flexible framework would be
 * nice. */
void rx_live(struct libusb_device_handle* devh, btbb_piconet* pn, int timeout)
{
	int r = btbb_init(max_ac_errors);
	if (r < 0)
		return;

	if (timeout)
		set_timeout(timeout);

	if (follow_pn)
		cmd_set_clock(devh, 0);
	else {
		stream_rx_usb(devh, XFER_LEN, 0, cb_br_rx, pn);
		/* Allow pending transfers to finish */
		sleep(1);
	}
	/* Used when follow_pn is preset OR set by stream_rx_usb above
	 * i.e. This cannot be rolled in to the above if...else
	 */
	if (follow_pn) {
		cmd_stop(devh);
		cmd_set_bdaddr(devh, btbb_piconet_get_bdaddr(follow_pn));
		cmd_start_hopping(devh, btbb_piconet_get_clk_offset(follow_pn));
		stream_rx_usb(devh, XFER_LEN, 0, cb_br_rx, follow_pn);
	}
}
Exemplo n.º 3
0
void cleanup(int sig)
{
	sig = sig;
	if (devh) {
		cmd_stop(devh);
		ubertooth_stop(devh);
	}
	exit(0);
}
Exemplo n.º 4
0
int exec_parsed(){
    // Execs a parsed command line.
    int error=0,i,got=-1,n;

    // Now execute the command.
    if(parse_nwords!=0){
         // Search for a matching known command.
         for(i=0;i<max_cmds;i++){
             if(strcmp(con_cmds[i].name,parse_words[0])==0){
                got=i;
             }
         }

         if(got>=0){
             // Make sure that we have the correct number of arguments for a command.
             if(con_cmds[got].type=='C'){
                 if(parse_nwords!=con_cmds[got].max+1){
                     got=-2;
                 }
             }
             // If we have a variable, deal with it here.
             else{
                 // No arguments means view the variable.
                 if(parse_nwords==1){
                     view_variable(got);
                     got=1000;
                 }

                 // One argument means set the variable.
                 if(parse_nwords==2){

                     // Find the value to set the variable to.
                     if(con_cmds[got].type=='F'){
                         // It's a FIXED variable.
                         n=ftofix(atof(parse_words[1]));
                     }
                     if(con_cmds[got].type=='I'){
                         // It's an INT.
                         n=atoi(parse_words[1]);
                     }
                     if(con_cmds[got].type=='S'){
                         // It's a string.
                         internal_setstring(con_cmds[got].s_mirror,parse_words[1]);
                     }
                     else{
                         // Put the value within limits.
                         if(n<con_cmds[got].min){n=con_cmds[got].min;}
                         if(n>con_cmds[got].max){n=con_cmds[got].max;}

                         // Set the mirror to the value.
                         con_cmds[got].mirror=n;
                     }
                 }

                 // If we don't have one or two arguments, then its an error.
                 if(parse_nwords>2){
                     got=-2;
                 }
             }
         }

         // Execute an actual command, or set a given variable.
         switch(got){
             case -1: internal_error();break;
             case  0: cmd_clear();break;
             case  1: player_crosshair=n;break;
             case  2: player_crosshair_color=n;break;
             case  3: cmd_dir();break;
             case  4: cmd_disconnect();break;
             case  5: cmd_exec();break;
             case  6: player_floors=n;break;
             case  7: player_fov_degrees=fixtof(n);break;
             case  8: player_fps=n;break;
             case  9: player_gamma=n;cmd_gamma();break;
             case 10: player_gfx_mode=n;cmd_gfx_mode();break;
             case 11: cmd_gfx_modes();break;
             case 12: player_heightfix=n;break;
             case 13: player_invert=n;break;
             case 14: light_con=n;break;
             case 15: light_depth=fixtof(n);break;
             case 16: cmd_loopdemo();break;
             case 17: cmd_map();break;
             case 18: cmd_mapinfo();break;
             case 19: player_map_rotate=n;break;
             case 20: player_map=n;break;
             case 21: player_map_size=n;break;
             case 22: cmd_mem();break;
             case 23: internal_setstring(player_pic_con,parse_words[1]);
                      cmd_pic_con();break;
             case 24: cmd_playdemo();break;
             case 25: cmd_pwad();break;
             case 26: cmd_quit();break;
             case 27: cmd_recdemo();break;
             case 28: player_r_grad=n;break;
             case 29: player_r_gun=n;break;
             case 30: cmd_stop();break;
             case 31: cmd_syntax();break;
             case 32: cmd_time();break;
             case 33: cmd_timerefresh();break;
             case 34: player_trace=1;break;
             case 35: cmd_viewpic();break;
             case 36: cmd_viewtex();break;
             case 37: player_vsync=n;break;
             case 38: cmd_wads();break;
             case 39: player_walls=n;break;
             case 40: player_windowsize=n;break;
         }
    }

    // Return the error value. DEBUG: Do we use this?
    return(error);
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	int opt;
	int r = 0;
	ubertooth_t* ut = NULL;
	rangetest_result rr;
	int do_stop, do_flash, do_isp, do_leds, do_part, do_reset;
	int do_serial, do_tx, do_palevel, do_channel, do_led_specan;
	int do_range_test, do_repeater, do_firmware, do_board_id;
	int do_range_result, do_all_leds, do_identify;
	int do_set_squelch, do_get_squelch, squelch_level;
	int do_something, do_compile_info;
	char ubertooth_device = -1;

	/* set command states to negative as a starter
	 * setting to 0 means 'do it'
	 * setting to positive is value of specified argument */
	do_stop= do_flash= do_isp= do_leds= do_part= do_reset= -1;
	do_serial= do_tx= do_palevel= do_channel= do_led_specan= -1;
	do_range_test= do_repeater= do_firmware= do_board_id= -1;
	do_range_result= do_all_leds= do_identify= -1;
	do_set_squelch= -1, do_get_squelch= -1; squelch_level= 0;
	do_something= 0; do_compile_info= -1;

	while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::9V")) != EOF) {
		switch(opt) {
		case 'U': 
			ubertooth_device = atoi(optarg);
			break;
		case 'f':
			fprintf(stderr, "ubertooth-util -f is no longer required - use ubertooth-dfu instead\n");
			do_flash= 0;
			break;
		case 'i':
			do_isp= 0;
			break;
		case 'I':
			do_identify= 0;
			break;
		case 'l':
			if (optarg)
				do_leds= atoi(optarg);
			else
				do_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'd':
			if (optarg)
				do_all_leds= atoi(optarg);
			else
				do_all_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'p':
			do_part= 0;
			break;
		case 'r':
			do_reset= 0;
			break;
		case 's':
			do_serial= 0;
			break;
		case 'S':
			do_stop= 0;
			break;
		case 't':
			do_tx= 0;
			break;
		case 'a':
			if (optarg)
				do_palevel= atoi(optarg);
			else
				do_palevel= 0;
			break;
		case 'C':
			if (optarg)
				do_channel= atoi(optarg) +2402;
			else
				do_channel= 0;
			break;	
		case 'c':
			if (optarg)
				do_channel= atoi(optarg);
			else
				do_channel= 0;
			break;
		case 'q':
			if (optarg)
				do_led_specan= atoi(optarg);
			else
				do_led_specan= 0;
			break;
		case 'n':
			do_range_test= 0;
			break;
		case 'm':
			do_range_result= 0;
			break;
		case 'e':
			do_repeater= 0;
			break;
		case 'v':
			do_firmware= 0;
			break;
		case 'b':
			do_board_id= 0;
			break;
		case 'z':
			if (optarg) {
				squelch_level = atoi(optarg);
				do_set_squelch = 1;
			}
			else {
				do_get_squelch = 1;
			}
			break;
		case '9':
			do_something= 1;
			break;
		case 'V':
			do_compile_info = 0;
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}

	/* initialise device */
	ut = ubertooth_start(ubertooth_device);
	if (ut == NULL) {
		usage();
		return 1;
	}
	if(do_reset == 0) {
		printf("Resetting ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		r = cmd_reset(ut->devh);
		sleep(2);
		ut = ubertooth_start(ubertooth_device);
	}
	if(do_stop == 0) {
		printf("Stopping ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		r = cmd_stop(ut->devh);
	}

	/* device configuration actions */
	if(do_all_leds == 0 || do_all_leds == 1) {
		cmd_set_usrled(ut->devh, do_all_leds);
		cmd_set_rxled(ut->devh, do_all_leds);
		r= cmd_set_txled(ut->devh, do_all_leds);
		r = (r >= 0) ? 0 : r;
	}
	if(do_channel > 0)
		r= cmd_set_channel(ut->devh, do_channel);
	if(do_leds == 0 || do_leds == 1)
		r= cmd_set_usrled(ut->devh, do_leds);
	if(do_palevel > 0)
		r= cmd_set_palevel(ut->devh, do_palevel);
	
	/* reporting actions */
	if(do_all_leds == 2) {
		printf("USR LED status: %d\n", cmd_get_usrled(ut->devh));
		printf("RX LED status : %d\n", cmd_get_rxled(ut->devh));
		printf("TX LED status : %d\n", r= cmd_get_txled(ut->devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_board_id == 0) {
		r= cmd_get_board_id(ut->devh);
		printf("Board ID Number: %d (%s)\n", r, board_names[r]);
	}
	if(do_channel == 0) {
		r= cmd_get_channel(ut->devh);
		printf("Current frequency: %d MHz (Bluetooth channel %d)\n", r, r - 2402);
		}
	if(do_firmware == 0) {
		char version[255];
		cmd_get_rev_num(ut->devh, version, (u8)sizeof(version));
		printf("Firmware revision: %s\n", version);
        }
	if(do_compile_info == 0) {
		char compile_info[255];
		cmd_get_compile_info(ut->devh, compile_info, (u8)sizeof(compile_info));
		puts(compile_info);
	}
	if(do_leds == 2)
		printf("USR LED status: %d\n", r= cmd_get_usrled(ut->devh));
	if(do_palevel == 0)
		printf("PA Level: %d\n", r= cmd_get_palevel(ut->devh));
	if(do_part == 0) {
		printf("Part ID: %X\n", r = cmd_get_partnum(ut->devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_range_result == 0) {
		r = cmd_get_rangeresult(ut->devh, &rr);
		if (r == 0) {
			if (rr.valid==1) {
				printf("request PA level : %d\n", rr.request_pa);
				printf("request number   : %d\n", rr.request_num);
				printf("reply PA level   : %d\n", rr.reply_pa);
				printf("reply number     : %d\n", rr.reply_num);
			} else if (rr.valid>1) {
				printf("Invalid range test: mismatch on byte %d\n", rr.valid-2);
			} else {
				printf("invalid range test result\n");
			}
		}
	}
	if(do_serial == 0) {
		u8 serial[17];
		r= cmd_get_serial(ut->devh, serial);
		if(r==0) {
			print_serial(serial, NULL);
		}
		// FIXME: Why do we do this to non-zero results?
		r = (r >= 0) ? 0 : r;
	}

	/* final actions */
	if(do_flash == 0) {
		printf("Entering flash programming (DFU) mode\n");
		return cmd_flash(ut->devh);
	}
	if(do_identify == 0) {
		printf("Flashing LEDs on ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		while(42) {
			do_identify= !do_identify;
			cmd_set_usrled(ut->devh, do_identify);
			cmd_set_rxled(ut->devh, do_identify);
			cmd_set_txled(ut->devh, do_identify);
			sleep(1);
		}
	}
	if(do_isp == 0) {
		printf("Entering flash programming (ISP) mode\n");
		return cmd_set_isp(ut->devh);
	}
	if(do_led_specan >= 0) {
		do_led_specan= do_led_specan ? do_led_specan : 225;
		printf("Entering LED specan mode (RSSI %d)\n", do_led_specan);
		return cmd_led_specan(ut->devh, do_led_specan);
	}
	if(do_range_test == 0) {
		printf("Starting range test\n");
		return cmd_range_test(ut->devh);
	}
	if(do_repeater == 0) {
		printf("Starting repeater\n");
		return cmd_repeater(ut->devh);
	}
	if(do_tx == 0) {
		printf("Starting TX test\n");
		return cmd_tx_test(ut->devh);
	}
	if(do_set_squelch > 0) {
		printf("Setting squelch to %d\n", squelch_level);
		cmd_set_squelch(ut->devh, squelch_level);
	}
	if(do_get_squelch > 0) {
		r = cmd_get_squelch(ut->devh);
		printf("Squelch set to %d\n", (int8_t)r);
	}
	if(do_something) {
		unsigned char buf[4] = { 0x55, 0x55, 0x55, 0x55 };
		cmd_do_something(ut->devh, NULL, 0);
		cmd_do_something_reply(ut->devh, buf, 4);
		printf("%02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);
		return 0;
	}

	return r;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	int opt;
	int r = 0;
	struct libusb_device_handle *devh= NULL;
	rangetest_result rr;
	int do_stop, do_flash, do_isp, do_leds, do_part, do_reset;
	int do_serial, do_tx, do_palevel, do_channel, do_led_specan;
	int do_range_test, do_repeater, do_firmware, do_board_id;
	int do_range_result, do_all_leds, do_identify;
	int do_set_squelch, do_get_squelch, squelch_level;

	/* set command states to negative as a starter
	 * setting to 0 means 'do it'
	 * setting to positive is value of specified argument */
	do_stop= do_flash= do_isp= do_leds= do_part= do_reset= -1;
	do_serial= do_tx= do_palevel= do_channel= do_led_specan= -1;
	do_range_test= do_repeater= do_firmware= do_board_id= -1;
	do_range_result= do_all_leds= do_identify= -1;
	do_set_squelch= -1, do_get_squelch= -1; squelch_level= 0;

	while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::")) != EOF) {
		switch(opt) {
		case 'U': 
			Ubertooth_Device= atoi(optarg);
                        break;
		case 'f':
			do_flash= 0;
			break;
		case 'i':
			do_isp= 0;
			break;
		case 'I':
			do_identify= 0;
			break;
		case 'l':
			if (optarg)
				do_leds= atoi(optarg);
			else
				do_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'd':
			if (optarg)
				do_all_leds= atoi(optarg);
			else
				do_all_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'p':
			do_part= 0;
			break;
		case 'r':
			do_reset= 0;
			break;
		case 's':
			do_serial= 0;
			break;
		case 'S':
			do_stop= 0;
			break;
		case 't':
			do_tx= 0;
			break;
		case 'a':
			if (optarg)
				do_palevel= atoi(optarg);
			else
				do_palevel= 0;
			break;
		case 'C':
                        if (optarg)
				do_channel= atoi(optarg) +2402;
                        else
				do_channel= 0;
                        break;
	
		case 'c':
			if (optarg)
				do_channel= atoi(optarg);
			else
				do_channel= 0;
			break;
		case 'q':
			if (optarg)
				do_led_specan= atoi(optarg);
			else
				do_led_specan= 0;
			break;
		case 'n':
			do_range_test= 0;
			break;
		case 'm':
			do_range_result= 0;
			break;
		case 'e':
			do_repeater= 0;
			break;
		case 'v':
			do_firmware= 0;
			break;
		case 'b':
			do_board_id= 0;
			break;
		case 'z':
			if (optarg) {
				squelch_level = atoi(optarg);
				do_set_squelch = 1;
			}
			else {
				do_get_squelch = 1;
			}
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}

	/* initialise device */
	devh = ubertooth_start();
	if (devh == NULL) {
		usage();
		return 1;
	}
	if(do_reset == 0) {
		printf("Resetting ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		r= cmd_reset(devh);
		sleep(2);
		devh = ubertooth_start();
	}
	if(do_stop == 0) {
		printf("Stopping ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		r= cmd_stop(devh);
	}

	/* device configuration actions */
	if(do_all_leds == 0 || do_all_leds == 1) {
		cmd_set_usrled(devh, do_all_leds);
		cmd_set_rxled(devh, do_all_leds);
		r= cmd_set_txled(devh, do_all_leds);
		r = (r >= 0) ? 0 : r;
	}
	if(do_channel > 0)
		r= cmd_set_channel(devh, do_channel);
	if(do_leds == 0 || do_leds == 1)
		r= cmd_set_usrled(devh, do_leds);
	if(do_palevel > 0)
		r= cmd_set_palevel(devh, do_palevel);
	
	/* reporting actions */
	if(do_all_leds == 2) {
		printf("USR LED status: %d\n", cmd_get_usrled(devh));
		printf("RX LED status : %d\n", cmd_get_rxled(devh));
		printf("TX LED status : %d\n", r= cmd_get_txled(devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_board_id == 0) {
		r= cmd_get_board_id(devh);
		printf("Board ID Number: %d (%s)\n", r, board_names[r]);
	}
	if(do_channel == 0) {
		r= cmd_get_channel(devh);
		printf("Current frequency: %d MHz (Bluetooth channel %d)\n", r, r - 2402);
		}
	if(do_firmware == 0)
		printf("Firmare revision: %d\n", r= cmd_get_rev_num(devh));
	if(do_leds == 2)
		printf("USR LED status: %d\n", r= cmd_get_usrled(devh));
	if(do_palevel == 0)
		printf("PA Level: %d\n", r= cmd_get_palevel(devh));
	if(do_part == 0) {
		printf("Part ID: %X\n", r = cmd_get_partnum(devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_range_result == 0) {
		r = cmd_get_rangeresult(devh, &rr);
		if (r == 0) {
			if (rr.valid) {
				printf("request PA level : %d\n", rr.request_pa);
				printf("request number   : %d\n", rr.request_num);
				printf("reply PA level   : %d\n", rr.reply_pa);
				printf("reply number     : %d\n", rr.reply_num);
			} else {
				printf("invalid range test result\n");
			}
		}
	}
	if(do_serial == 0) {
		printf("Serial No: ");
		r= cmd_get_serial(devh);
		r = (r >= 0) ? 0 : r;
	}

	/* final actions */
	if(do_flash == 0) {
		printf("Entering flash programming (DFU) mode\n");
		return cmd_flash(devh);
	}
	if(do_identify == 0) {
		printf("Flashing LEDs on ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		while(42) {
			do_identify= !do_identify;
			cmd_set_usrled(devh, do_identify);
			cmd_set_rxled(devh, do_identify);
			cmd_set_txled(devh, do_identify);
			sleep(1);
		}
	}
	if(do_isp == 0) {
		printf("Entering flash programming (ISP) mode\n");
		return cmd_set_isp(devh);
	}
	if(do_led_specan >= 0) {
		do_led_specan= do_led_specan ? do_led_specan : 225;
		printf("Entering LED specan mode (RSSI %d)\n", do_led_specan);
		return cmd_led_specan(devh, do_led_specan);
	}
	if(do_range_test == 0) {
		printf("Starting range test\n");
		return cmd_range_test(devh);
	}
	if(do_repeater == 0) {
		printf("Starting repeater\n");
		return cmd_repeater(devh);
	}
	if(do_tx == 0) {
		printf("Starting TX test\n");
		return cmd_tx_test(devh);
	}
	if(do_set_squelch > 0) {
		printf("Setting squelch to %d\n", squelch_level);
		cmd_set_squelch(devh, squelch_level);
	}
	if(do_get_squelch > 0) {
		r = cmd_get_squelch(devh);
		printf("Squelch set to %d\n", (int8_t)r);
	}

	return r;
}
Exemplo n.º 7
0
void edje_cb_stop (void *data, Evas_Object *eo, const char *emission, const char *source) {
	cmd_stop((rockon_data*)data);
}
Exemplo n.º 8
0
void elm_cb_stop(void *data, Evas_Object *obj, void *event_info) {
	cmd_stop((rockon_data*)data);
}