Example #1
0
int main(int argc, char *argv[])
{
	int opt, have_lap = 0, have_uap = 0;
	int timeout = 0;
	int reset_scan = 0;
	char *end;
	char ubertooth_device = -1;
	btbb_piconet *pn = NULL;
	uint32_t lap = 0;
	uint8_t uap = 0;

	while ((opt=getopt(argc,argv,"hVi:l:u:U:d:e:r:sq:t:")) != EOF) {
		switch(opt) {
		case 'i':
			infile = fopen(optarg, "r");
			if (infile == NULL) {
				printf("Could not open file %s\n", optarg);
				usage();
				return 1;
			}
			break;
		case 'l':
			lap = strtol(optarg, &end, 16);
			have_lap++;
			break;
		case 'u':
			uap = strtol(optarg, &end, 16);
			have_uap++;
			break;
		case 'U':
			ubertooth_device = atoi(optarg);
			break;
		case 'r':
			if (!h_pcapng_bredr) {
				if (btbb_pcapng_create_file( optarg, "Ubertooth", &h_pcapng_bredr )) {
					err(1, "create_bredr_capture_file: ");
				}
			}
			else {
				printf("Ignoring extra capture file: %s\n", optarg);
			}
			break;
#ifdef ENABLE_PCAP
		case 'q':
			if (!h_pcap_bredr) {
				if (btbb_pcap_create_file(optarg, &h_pcap_bredr)) {
					err(1, "btbb_pcap_create_file: ");
				}
			}
			else {
				printf("Ignoring extra capture file: %s\n", optarg);
			}
			break;
#endif
		case 'd':
			dumpfile = fopen(optarg, "w");
			if (dumpfile == NULL) {
				perror(optarg);
				return 1;
			}
			break;
		case 'e':
			max_ac_errors = atoi(optarg);
			break;
		case 's':
			++reset_scan;
			break;
		case 't':
			timeout = atoi(optarg);
			break;
		case 'V':
			print_version();
			return 0;
		case 'h':
		default:
			usage();
			return 1;
		}
	}

	if (have_lap) {
		pn = btbb_piconet_new();
		btbb_init_piconet(pn, lap);
		if (have_uap)
			btbb_piconet_set_uap(pn, uap);
		if (h_pcapng_bredr) {
			btbb_pcapng_record_bdaddr(h_pcapng_bredr,
						  (((uint32_t)uap)<<24)|lap,
						  have_uap ? 0xff : 0x00, 0);
		}
	} else if (have_uap) {
		printf("Error: UAP but no LAP specified\n");
		usage();
		return 1;
	}

	if (infile == NULL) {
		devh = ubertooth_start(ubertooth_device);
		if (devh == NULL) {
			usage();
			return 1;
		}

		/* Scan all frequencies. Same effect as
		 * ubertooth-utils -c9999. This is necessary after
		 * following a piconet. */
		if (reset_scan) {
			cmd_set_channel(devh, 9999);
		}

		/* Clean up on exit. */
		register_cleanup_handler(devh);

		rx_live(devh, pn, timeout);

		// Print AFH map from piconet if we have one
		if (pn)
			btbb_print_afh_map(pn);

		ubertooth_stop(devh);
	} else {
		rx_file(infile, pn);
		fclose(infile);
	}

	return 0;
}
Example #2
0
QVector <QStringList> Parser::polyOptParser(QString str)
{
    QString ext = QString("(\\*\\.\\w+,?\\s?)");
    QString f = QString("(\\^\\*?\\??\\w+\\*?\\??,?\\s?)");
    QString opt_opt = QString("(-[hrdsa]+[^elp]+)");
    QString opt_help = QString("(--help)");
    QString opt_ext = QString("(--ext:\"%1+\")").arg(ext);
    QString opt_f = QString("(--f:\"%1+\")").arg(f);
    QString path_address = QString("(\\w:\\\\.+\\b)(?=\\s+\\w:\\\\.+)");
    QString file_save_address = QString("\\w:\\\\.+(\\w:\\\\.+.txt)(?!\\w:\\\\.+)");
    QString opt = QString("%5\\s?%6\\s?%1?\\s?%2?\\s?%3?%4?\\s?").arg(opt_help).
                  arg(opt_opt).arg(opt_ext).arg(opt_f).arg(path_address).arg(file_save_address);

    QRegExp rx_ext(ext);
    QRegExp rx_f(f);
    QRegExp rx_opt_opt(opt_opt);
    QRegExp rx_opt_ext(opt_ext);
    QRegExp rx_opt_f(opt_f);
    QRegExp rx_opt_help(opt_help);
    QRegExp rx_path(path_address);
    QRegExp rx_file(file_save_address);
    QRegExp rx_opt(opt);

#ifdef DEBUG
    qDebug() << "rx_opt is valid?" << rx_opt.isValid();
    qDebug() << "str:" << str;
    qDebug() << "rx_opt.indexIn(str, 0) =" << rx_opt.indexIn(str, 0);
#endif

    QStringList listOpt;
    QStringList listExt;
    QStringList listFiles;
    QStringList listHelp;
    QStringList listPath;
    QStringList listFile;

    int pos = 0;

    QString stringExt;
    QString stringFiles;
    QString stringOpt;
    QString stringHelp;
    QString stringPath;
    QString stringFile;

    if((rx_opt.indexIn(str, 0) != -1) && (rx_opt_help.indexIn(str, 0) == -1))
    {
        while((pos = rx_path.indexIn(str, pos)) != -1)
        {
            stringPath = rx_path.cap(1);
            listPath.append(stringPath);
            pos += rx_path.matchedLength();
        }

        pos = 0;

        while((pos = rx_file.indexIn(str, pos)) != -1)
        {
            stringFile = rx_file.cap(1);
            listFile.append(stringFile);
            pos += rx_file.matchedLength();
        }

        pos = 0;

        if(rx_opt_opt.indexIn(str, 0) != -1)
        {
            while((pos = rx_opt_opt.indexIn(str, pos)) != -1)
            {
                stringOpt = rx_opt_opt.cap(1);
                listOpt.append(stringOpt);
                pos += rx_opt_opt.matchedLength();
            }
        }
        if(rx_opt_ext.indexIn(str, 0) !=-1)
        {
            pos = rx_opt_ext.indexIn(str, 0);

            while (((pos = rx_ext.indexIn(str, pos)) != -1) &&
                    ((pos < rx_opt_f.indexIn(str, 0)) || (rx_opt_f.indexIn(str, 0) == -1)))
            {
                stringExt = rx_ext.cap(1);
                listExt.append(stringExt);
                pos += rx_ext.matchedLength();
            }
        }
#ifdef DEBUG
        qDebug() << "rx_opt_f.indexIn(str, 0):" << rx_opt_f.indexIn(str, 0);
#endif
        if(rx_opt_f.indexIn(str, 0) !=-1)
        {
            pos = rx_opt_f.indexIn(str, 0);
            while ((pos = rx_f.indexIn(str, pos)) != -1)
            {
                stringFiles = rx_f.cap(1);
                listFiles.append(stringFiles);
                pos += rx_f.matchedLength();
#ifdef DEBUG
                qDebug() << "stringFiles:" << stringFiles;
#endif
            }
        }
    }
    else if((rx_opt_help.indexIn(str, 0) != -1) && (rx_opt.indexIn(str, 0) != -1))
    {
        stringHelp = rx_opt_help.cap(0);
        listHelp.append(stringHelp);
    }
    else
    {
        qErrnoWarning("Incorrect input options!");
    }

    QStringList sl;

    foreach (QString temp_str, listOpt) {
        sl.append(temp_str.replace(QRegExp("-"), "").split(QRegExp("(?=\\w)"), QString::SkipEmptyParts));
    }
Example #3
0
int main(int argc, char *argv[])
{
	int opt, have_lap = 0, have_uap = 0;
	int reset_scan = 0;
	char *end;
	char ubertooth_device = -1;
	btbb_piconet *pn = NULL;
	uint32_t lap;
	uint8_t uap;

	while ((opt=getopt(argc,argv,"hi:l:u:U:d:e:sc:")) != EOF) {
		switch(opt) {
		case 'i':
			infile = fopen(optarg, "r");
			if (infile == NULL) {
				printf("Could not open file %s\n", optarg);
				usage();
				return 1;
			}
			break;
		case 'l':
			lap = strtol(optarg, &end, 16);
			have_lap++;
			break;
		case 'u':
			uap = strtol(optarg, &end, 16);
			have_uap++;
			break;
		case 'U':
			ubertooth_device = atoi(optarg);
			break;
		case 'c':
#ifdef USE_PCAP
			pcap_dumpfile = pcap_open_dead(DLT_PPI, 128);
			if (pcap_dumpfile == NULL)
				err(1, "pcap_open_dead: ");
			dumper = pcap_dump_open(pcap_dumpfile, optarg);
			pcap_dump_flush(dumper);
			if (dumper == NULL) {
				warn("pcap_dump_open");
				pcap_close(pcap_dumpfile);
				exit(1);
			}
#else
                        printf("Not compiled with 'USE_PCAP', -c ignored\n");
#endif // USE_PCAP
			break;
		case 'd':
			dumpfile = fopen(optarg, "w");
			if (dumpfile == NULL) {
				perror(optarg);
				return 1;
			}
			break;
		case 'e':
			max_ac_errors = atoi(optarg);
			break;
		case 's':
			++reset_scan;
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}
	
	if (have_lap) {
		pn = btbb_piconet_new();
		btbb_init_piconet(pn, lap);
		if (have_uap)
			btbb_piconet_set_uap(pn, uap);
	} else if (have_uap) {
		printf("Error: UAP but no LAP specified\n");
		usage();
		return 1;
	}

	if (infile == NULL) {
		devh = ubertooth_start(ubertooth_device);
		if (devh == NULL) {
			usage();
			return 1;
		}

		/* Scan all frequencies. Same effect as
		 * ubertooth-utils -c9999. This is necessary after
		 * following a piconet. */
		if (reset_scan) {
			cmd_set_channel(devh, 9999);
		}

		/* Clean up on exit. */
		signal(SIGINT,cleanup);
		signal(SIGQUIT,cleanup);
		signal(SIGTERM,cleanup);

		rx_live(devh, pn, 0);

		// Print AFH map from piconet if we have one
		if (pn)
			btbb_print_afh_map(pn);

		ubertooth_stop(devh);
	} else {
		rx_file(infile, pn);
		fclose(infile);
	}

	return 0;
}