diff --git a/.travis.yml b/.travis.yml index 0b052044a..f8cf8228f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ addons: packages: - gcc-arm-none-eabi - libnewlib-dev + - libbluetooth-dev homebrew: packages: - readline diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 0bbf1067c..921e0d04b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -35,6 +35,9 @@ foreach(_qt_package IN LISTS QT_PACKAGELIST) endif(NOT ${_qt_package}_FOUND) endforeach() +find_package(PkgConfig) +pkg_search_module(BLUEZ QUIET bluez) + SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_subdirectory(deps) @@ -208,6 +211,12 @@ else (Qt5_FOUND) ${TARGET_SOURCES}) endif (Qt5_FOUND) +if (BLUEZ_FOUND) + message("Bluez library found, building native Bluetooth support :)") + add_definitions("-DHAVE_BLUEZ") + set(ADDITIONAL_LNK bluetooth ${ADDITIONAL_LNK}) +endif (BLUEZ_FOUND) + add_executable( proxmark3 ${TARGET_SOURCES} diff --git a/client/Makefile b/client/Makefile index d3461a302..d7709f656 100644 --- a/client/Makefile +++ b/client/Makefile @@ -90,6 +90,14 @@ else endif endif +ifneq ($(SKIPBT),1) + BTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs bluez 2>/dev/null) +endif + +ifneq ($(BTLDLIBS),) + PM3CFLAGS += -DHAVE_BLUEZ +endif + ifneq ($(SKIPQT),1) # Check for correctly configured Qt5 QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null) @@ -132,6 +140,24 @@ else QTGUIOBJS = $(OBJDIR)/guidummy.o endif +$(info ===================================================================) +$(info Client platform: $(platform)) +ifeq ($(SKIPQT),1) +$(info GUI support: skipped) +else ifneq ($(QTLDLIBS),) +$(info GUI support: QT found, enabled) +else +$(info GUI support: QT not found, disabled) +endif +ifeq ($(SKIPBT),1) +$(info native BT support: skipped) +else ifneq ($(BTLDLIBS),) +$(info native BT support: Bluez found, enabled) +else +$(info native BT support: Bluez not found, disabled) +endif +$(info ===================================================================) + # Flags to generate temporary dependency files DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td # make temporary to final dependency files after successful compilation @@ -286,7 +312,7 @@ all: $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) -proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(CLIPARSERLIB) $(QTLDLIBS) +proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(CLIPARSERLIB) $(BTLDLIBS) $(QTLDLIBS) proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(CLIPARSERLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LDLIBS) -o $@ diff --git a/client/src/comms.c b/client/src/comms.c index 88ffde16c..36f035bdd 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -639,9 +639,10 @@ int TestProxmark(void) { conn.send_via_fpc_usart = pm3_capabilities.via_fpc; conn.uart_speed = pm3_capabilities.baudrate; - PrintAndLogEx(INFO, "Communicating with PM3 over %s%s", + PrintAndLogEx(INFO, "Communicating with PM3 over %s%s%s", conn.send_via_fpc_usart ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"), - memcmp(conn.serial_port_name, "tcp:", 4) == 0 ? " over " _YELLOW_("TCP") : ""); + memcmp(conn.serial_port_name, "tcp:", 4) == 0 ? " over " _YELLOW_("TCP") : "", + memcmp(conn.serial_port_name, "bt:", 3) == 0 ? " over " _YELLOW_("BT") : ""); if (conn.send_via_fpc_usart) { PrintAndLogEx(INFO, "PM3 UART serial baudrate: " _YELLOW_("%u") "\n", conn.uart_speed); diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index a2b324b49..cf0837845 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -48,10 +48,16 @@ #include #include #include -#include "sys/socket.h" -#include "sys/un.h" +#include +#include + +#ifdef HAVE_BLUEZ +#include +#include +#endif #include "comms.h" +#include "ui.h" // Taken from https://github.com/unbit/uwsgi/commit/b608eb1772641d525bfde268fe9d6d8d0d5efde7 #ifndef SOL_TCP @@ -158,6 +164,52 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) { return sp; } + if (memcmp(pcPortName, "bt:", 3) == 0) { +#ifdef HAVE_BLUEZ + if (strlen(pcPortName) != 20) { + free(sp); + return INVALID_SERIAL_PORT; + } + char *addrstr = strndup(pcPortName + 3, 17); + + if (addrstr == NULL) { + printf("Error: malloc\n"); + free(sp); + return INVALID_SERIAL_PORT; + } + + struct sockaddr_rc addr = { 0 }; + addr.rc_family = AF_BLUETOOTH; + addr.rc_channel = (uint8_t) 1; + if (str2ba(addrstr, &addr.rc_bdaddr) != 0) { + PrintAndLogEx(ERR, "Invalid Bluetooth MAC address " _RED_("%s"), addrstr); + free(addrstr); + free(sp); + return INVALID_SERIAL_PORT; + } + int sfd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if (sfd == -1) { + PrintAndLogEx(ERR, "Error opening Bluetooth socket"); + free(addrstr); + free(sp); + return INVALID_SERIAL_PORT; + } + if (connect(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + PrintAndLogEx(ERR, "Error: cannot connect device " _YELLOW_("%s") " over Bluetooth", addrstr); + close(sfd); + free(addrstr); + free(sp); + return INVALID_SERIAL_PORT; + } + + sp->fd = sfd; + return sp; +#else // HAVE_BLUEZ + PrintAndLogEx(ERR, "Sorry, this client doesn't support native Bluetooth addresses"); + free(sp); + return INVALID_SERIAL_PORT; +#endif // HAVE_BLUEZ + } // The socket for abstract namespace implement. // Is local socket buffer, not a TCP or any net connection! // so, you can't connect with address like: 127.0.0.1, or any IP diff --git a/doc/bt_manual_v10.md b/doc/bt_manual_v10.md index 38f5f0d3b..c009ba025 100644 --- a/doc/bt_manual_v10.md +++ b/doc/bt_manual_v10.md @@ -102,7 +102,9 @@ http://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp #### Linux -#### (1) Connecting rdv4.0 with Bluetooth on Linux computer +#### (1) Connecting rdv4.0 with Bluetooth on Linux computer via native Bluetooth support in the client + +This requires to have compiled the client with Bluetooth support. 1. Find the MAC address of the Bluetooth add-on, named PM3_RDV4.0. @@ -114,21 +116,9 @@ Scanning ... Instead of `aa:bb:cc:dd:ee:ff`, you'll see your MAC address. -2. Bind your BT add-on MAC address to a serial port +2. Use Proxmark client with Bluetooth MAC address as bt: ```sh -sudo rfcomm bind rfcomm0 aa:bb:cc:dd:ee:ff -``` - -Replace `aa:bb:cc:dd:ee:ff` by your MAC address. - -3. The blue state LED on the add-on will keep blinking after the -connection is established. Only when the Proxmark3 client opens the -`/dev/rfcomm0` port, the blue LED turns on solid, indicating that the -connection is successful. - -4. Use Proxmark client on BT-serial port -```sh -./proxmark3 /dev/rfcomm0 +./proxmark3 bt:aa:bb:cc:dd:ee:ff ``` The first time, your OS will ask you for pairing. The default PIN is 1234. If PIN is not typed in quickly, the client might timeout. Simply @@ -172,6 +162,39 @@ turn on solid. ./proxmark3 /dev/ttyUSB0 ``` +#### (1b, deprecated) Connecting rdv4.0 with Bluetooth on Linux computer via rfcomm + +rfcomm is a deprecated tool which might be unavailable in your Linux distribution. + +1. Find the MAC address of the Bluetooth add-on, named PM3_RDV4.0. + +```sh +sudo hcitool scan +Scanning ... + aa:bb:cc:dd:ee:ff PM3_RDV4.0 +``` + +Instead of `aa:bb:cc:dd:ee:ff`, you'll see your MAC address. + +2. Bind your BT add-on MAC address to a serial port +```sh +sudo rfcomm bind rfcomm0 aa:bb:cc:dd:ee:ff +``` + +Replace `aa:bb:cc:dd:ee:ff` by your MAC address. + +3. The blue state LED on the add-on will keep blinking after the +connection is established. Only when the Proxmark3 client opens the +`/dev/rfcomm0` port, the blue LED turns on solid, indicating that the +connection is successful. + +4. Use Proxmark client on BT-serial port +```sh +./proxmark3 /dev/rfcomm0 +``` + +See instructions above (method 1) for initial pairing. + #### MacOS #### (1) Connecting rdv4.0 with Bluetooth on MacOS diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index b381eb7d9..8cb6b47ff 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -25,9 +25,11 @@ Install the requirements ```sh sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \ -libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev +libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbluetooth-dev ``` +If you don't need the native Bluetooth support in the client, you can skip the installation of `libbluetooth-dev`. + If you don't need the graphical components of the Proxmark3 client (such as in `hw tune`), you can skip the installation of `qtbase5-dev`. If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to load module "canberra-gtk-module"_ you may have to install `libcanberra-gtk-module`. @@ -35,17 +37,21 @@ If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to ## On ArchLinux ```sh -sudo pacman -Sy git base-devel readline arm-none-eabi-gcc arm-none-eabi-newlib qt5-base --needed +sudo pacman -Sy git base-devel readline arm-none-eabi-gcc arm-none-eabi-newlib qt5-base bluez --needed ``` +If you don't need the native Bluetooth support in the client, you can skip the installation of `bluez`. + If you don't need the graphical components of the Proxmark3 client (such as in `hw tune`), you can skip the installation of `qt5-base`. ## On Fedora ```sh -sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel libatomic +sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel bluez-libs-devel libatomic ``` +If you don't need the native Bluetooth support in the client, you can skip the installation of `bluez-libs-devel`. + If you don't need the graphical components of the Proxmark3 client (such as in `hw tune`), you can skip the installation of `qt5-qtbase-devel`. ## On openSUSE @@ -56,6 +62,8 @@ sudo zypper install git patterns-devel-base-devel_basis gcc-c++ readline-devel c If you don't need the graphical components of the Proxmark3 client (such as in `hw tune`), you can skip the installation of `libqt5-qtbase-devel`. +Note that Bluez is not available on openSUSE so the native Bluetooth support won't be available in the client. + # Clone the RRG/Iceman repository ```sh diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md index 5e953883a..46e1c6504 100644 --- a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -19,6 +19,14 @@ make clean make SKIPQT=1 ``` +On Linux hosts, if the Bluez headers and library are present, the client will be compiled with native Bluetooth support. It's possible to explicitly skip Bluetooth support with: + +``` +make clean +make SKIPBT=1 +``` + + ## Firmware By default, the firmware is of course tuned for the Proxmark3 Rdv4.0 device, which has built-in support for 256kb onboard flash SPI memory, Sim module (smart card support), FPC connector.