diff --git a/src/Makefile b/src/Makefile index 2f0640f0a..67144444a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,6 +45,9 @@ SYMBOLS += DEFAULT_ALLOW_RAW_WRITE_NETWORK=$(DEFAULT_ALLOW_RAW_WRITE_NETWORK) DEFAULT_ALLOW_RAW_WRITE_BLE ?= 0 SYMBOLS += DEFAULT_ALLOW_RAW_WRITE_BLE=$(DEFAULT_ALLOW_RAW_WRITE_BLE) +DEFAULT_BLUETOOTH_PIN ?= "\"1234\"" +SYMBOLS += DEFAULT_BLUETOOTH_PIN=$(DEFAULT_BLUETOOTH_PIN) + DEFAULT_METRICS_STATUS ?= 0 SYMBOLS += DEFAULT_METRICS_STATUS=$(DEFAULT_METRICS_STATUS) diff --git a/src/bluetooth.cpp b/src/bluetooth.cpp index 13aed5467..9c23a143c 100644 --- a/src/bluetooth.cpp +++ b/src/bluetooth.cpp @@ -5,6 +5,7 @@ #include "atcommander.h" #include "util/timer.h" #include "gpio.h" +#include "config.h" #include #define BLUETOOTH_DEVICE_NAME "OpenXC-VI" @@ -21,6 +22,7 @@ using openxc::gpio::GPIO_DIRECTION_OUTPUT; using openxc::gpio::GPIO_DIRECTION_INPUT; using openxc::gpio::GPIO_VALUE_HIGH; using openxc::gpio::GPIO_VALUE_LOW; +using openxc::config::getConfiguration; using openxc::util::time::delayMs; using openxc::util::log::debug; @@ -80,6 +82,18 @@ void openxc::bluetooth::configureExternalModule(UartDevice* device) { debug("Unable to disable remote Bluetooth configuration"); } + AtCommand pinCommand = { + request_format: "SP,%s\r", + expected_response: "AOK", + error_response: "ERR" + }; + + if(at_commander_set(&config, &pinCommand, getConfiguration()->bluetoothPin)) { + debug("Changed Bluetooth Pairing Pin to %s.", getConfiguration()->bluetoothPin); + } else { + debug("Unable to change Bluetooth Pairing Pin."); + } + AtCommand inquiryCommand = { request_format: "SI,%s\r", expected_response: "AOK", diff --git a/src/config.cpp b/src/config.cpp index cfa8490d8..bec4dd523 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -132,6 +132,7 @@ openxc::config::Configuration* openxc::config::getConfiguration() { desiredRunLevel: RunLevel::CAN_ONLY, initialized: false, runLevel: RunLevel::NOT_RUNNING, + bluetoothPin: DEFAULT_BLUETOOTH_PIN, uart: { descriptor: { allowRawWrites: DEFAULT_ALLOW_RAW_WRITE_UART diff --git a/src/config.h b/src/config.h index f0514bf3b..5f4c24fae 100644 --- a/src/config.h +++ b/src/config.h @@ -123,6 +123,7 @@ typedef struct { RunLevel desiredRunLevel; bool initialized; RunLevel runLevel; + const char* bluetoothPin; openxc::interface::uart::UartDevice uart; openxc::interface::network::NetworkDevice network; openxc::interface::usb::UsbDevice usb;