#include <cstring>
#include <string>
#include <memory>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <cinttypes>
#include <pthread.h>
#include <csignal>
extern "C" {
#include <unistd.h>
}
const static std::string
KEY_PATH =
"keys";
static bool QUIET =
false;
const AdapterSetting changedmask,
const uint64_t timestamp)
override {
if( initialSetting ) {
fprintf_td(stderr,
"****** SETTINGS_INITIAL: %s -> %s, changed %s\n",
to_string(oldmask).c_str(),
} else {
fprintf_td(stderr,
"****** SETTINGS_CHANGED: %s -> %s, changed %s\n",
to_string(oldmask).c_str(),
}
(void)timestamp;
if( !initialSetting &&
{
sd.detach();
}
}
void discoveringChanged(
BTAdapter &a,
const ScanType currentMeta,
const ScanType changedType,
const bool changedEnabled,
const bool keepAlive,
const uint64_t timestamp)
override {
fprintf_td(stderr,
"****** DISCOVERING: meta %s, changed[%s, enabled %d, keepAlive %d]: %s\n",
(void)timestamp;
}
bool deviceFound(std::shared_ptr<BTDevice> device,
const uint64_t timestamp)
override {
(void)timestamp;
fprintf_td(stderr,
"****** FOUND__-2: Skip non 'public LE' and non 'random static public LE' %s\n", device->
toString(
true).c_str());
return false;
}
)
)
)
{
{
fprintf_td(stderr,
"PERF: adapter-init -> FOUND__-0 %" PRIu64
" ms\n", td);
}
dc.detach();
return true;
} else {
return false;
}
}
void deviceUpdated(std::shared_ptr<BTDevice> device,
const EIRDataType updateMask,
const uint64_t timestamp)
override {
}
(void)timestamp;
}
void deviceConnected(std::shared_ptr<BTDevice> device, const uint16_t handle, const uint64_t timestamp) override {
(void)handle;
(void)timestamp;
}
void devicePairingState(std::shared_ptr<BTDevice> device,
const SMPPairingState state,
const PairingMode mode,
const uint64_t timestamp)
override {
fprintf_td(stderr,
"****** PAIRING STATE: state %s, mode %s, %s\n",
(void)timestamp;
switch( state ) {
break;
fprintf_td(stderr,
"****** PAIRING_STATE: state %s; Remove key file %s, res %d\n",
} break;
break;
break;
break;
dc.detach();
} else {
dc.detach();
}
} break;
if( nullptr != sec ) {
dc.detach();
} else {
dc.detach();
}
} break;
break;
break;
break;
default:
break;
}
}
void deviceReady(std::shared_ptr<BTDevice> device, const uint64_t timestamp) override {
(void)timestamp;
)
)
)
{
} else {
}
}
void deviceDisconnected(std::shared_ptr<BTDevice> device,
const HCIStatusCode reason,
const uint16_t handle,
const uint64_t timestamp)
override {
fprintf_td(stderr,
"****** DISCONNECTED: Reason 0x%X (%s), old handle %s: %s\n",
static_cast<uint8_t
>(reason),
to_string(reason).c_str(),
(void)timestamp;
dc.detach();
} else {
}
dc.detach();
}
}
std::string toString() const override {
return "MyAdapterStatusListener[this "+
to_hexstring(
this)+
"]";
}
};
private:
int i, j;
public:
void notificationReceived(
BTGattCharRef charDecl,
const TROOctets& char_value,
const uint64_t timestamp)
override {
fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic-Notify: UUID %s, td %" PRIu64
" ******\n",
i, j, charDecl->value_type->toUUID128String().c_str(), (tR-timestamp));
fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic: %s ******\n", i, j, charDecl->toString().c_str());
if( nullptr != temp ) {
fprintf_td(stderr,
"**[%2.2d.%2.2d] Value T: %s ******\n", i, j, temp->
toString().c_str());
}
}
fprintf_td(stderr,
"**[%2.2d.%2.2d] Value R: %s ******\n", i, j, char_value.
toString().c_str());
}
const TROOctets& char_value,
const uint64_t timestamp,
const bool confirmationSent) override
{
fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic-Indication: UUID %s, td %" PRIu64
", confirmed %d ******\n",
i, j, charDecl->value_type->toUUID128String().c_str(), (tR-timestamp), confirmationSent);
fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic: %s ******\n", i, j, charDecl->toString().c_str());
if( nullptr != temp ) {
fprintf_td(stderr,
"**[%2.2d.%2.2d] Value T: %s ******\n", i, j, temp->
toString().c_str());
}
}
fprintf_td(stderr,
"**[%2.2d.%2.2d] Value R: %s ******\n", i, j, char_value.
toString().c_str());
}
};
void deviceUpdated(std::shared_ptr<BTDevice> device,
const EIRDataType updateMask,
const uint64_t timestamp)
override {
}
(void)timestamp;
}
void deviceConnected(std::shared_ptr<BTDevice> device, const uint16_t handle, const uint64_t timestamp) override {
(void)handle;
(void)timestamp;
}
std::string toString() const override {
return "TempAdapterStatusListener[this "+
to_hexstring(
this)+
"]";
}
};
device->
addStatusListener(std::shared_ptr<AdapterStatusListener>(
new TempAdapterStatusListener()));
{
}
{
fprintf_td(stderr,
"****** Connecting Device: stopDiscovery result %s\n",
to_string(r).c_str());
}
if( nullptr != sec ) {
fprintf_td(stderr,
"****** Connecting Device: Found SecurityDetail %s for %s\n", sec->
toString().c_str(), device->
toString().c_str());
} else {
fprintf_td(stderr,
"****** Connecting Device: No SecurityDetail for %s\n", device->
toString().c_str());
}
fprintf_td(stderr,
"****** Connecting Device: SMPKeyBin::readAndApply(..) result %s\n",
to_string(res).c_str());
if( nullptr != sec ) {
fprintf_td(stderr,
"****** Connecting Device: Using SecurityDetail.SEC AUTO %s, set OK %d\n", sec->
toString().c_str(), r);
fprintf_td(stderr,
"****** Connecting Device: Using SecurityDetail.Level+IOCap %s, set OK %d\n", sec->
toString().c_str(), r);
} else {
fprintf_td(stderr,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY (%s) -> set OK %d\n", sec->
toString().c_str(), r);
}
} else {
fprintf_td(stderr,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY -> set OK %d\n", r);
}
}
} else {
}
}
}
fprintf_td(stderr,
"****** Processing Ready Device: Start %s\n", device->
toString().c_str());
bool success = false;
{
fprintf_td(stderr,
"****** Connected LE PHY: status %s: RX %s, TX %s\n",
}
}
try {
if( 0 == primServices.
size() ) {
fprintf_td(stderr,
"****** Processing Ready Device: getServices() failed %s\n", device->
toString().c_str());
goto exit;
}
const uint64_t td15 = t5 - t1;
fprintf_td(stderr,
"PERF: GATT primary-services completed\n");
fprintf_td(stderr,
"PERF: adapter-init to processing-start %" PRIu64
" ms,\n"
"PERF: get-gatt-services %" PRIu64 " ms,\n"
"PERF: discovered to gatt-complete %" PRIu64 " ms (connect %" PRIu64 " ms),\n"
"PERF: adapter-init to gatt-complete %" PRIu64 " ms\n\n",
td01, td15, tdc5, (tdc5 - td15), td05);
}
#if 0
{
if( nullptr != char2 ) {
bool cccdEnableResult[2];
cccdEnableResult );
fprintf_td(stderr,
"Added CharPingPongListenerRes Notification(%d), Indication(%d): Result %d\n",
cccdEnableResult[0], cccdEnableResult[1], cccdRet);
}
if( cccdRet ) {
}
}
}
}
}
#endif
if(
nullptr != ga && !
QUIET ) {
}
{
if(
nullptr != di && !
QUIET ) {
}
}
}
for(
size_t i=0; i<primServices.
size(); i++) {
fprintf_td(stderr,
" [%2.2d] Service UUID %s\n", i, primService.
type->toUUID128String().c_str());
}
for(
size_t j=0; j<serviceCharacteristics.
size(); j++) {
fprintf_td(stderr,
" [%2.2d.%2.2d] Characteristic: UUID %s\n", i, j, serviceChar.
value_type->toUUID128String().c_str());
}
fprintf_td(stderr,
" [%2.2d.%2.2d] value: %s ('%s')\n", (
int)i, (
int)j, value.toString().c_str(), sval.c_str());
}
}
}
for(
size_t k=0; k<charDescList.
size(); k++) {
fprintf_td(stderr,
" [%2.2d.%2.2d.%2.2d] Descriptor: UUID %s\n", i, j, k, charDesc.
type->toUUID128String().c_str());
}
}
bool cccdEnableResult[2];
cccdEnableResult );
fprintf_td(stderr,
" [%2.2d.%2.2d] Characteristic-Listener: Notification(%d), Indication(%d): Added %d\n",
(int)i, (int)j, cccdEnableResult[0], cccdEnableResult[1], cccdRet);
}
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
success = true;
} catch ( std::exception & e ) {
fprintf_td(stderr,
"****** Processing Ready Device: Exception caught for %s: %s\n", device->
toString().c_str(), e.what());
}
exit:
fprintf_td(stderr,
"****** Processing Ready Device: End-1: Success %d on %s; devInProc %zu\n",
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
}
fprintf_td(stderr,
"****** Processing Ready Device: End-2: Success %d on %s; devInProc %zu\n",
if( success ) {
}
{
fprintf_td(stderr,
"****** Processing Ready Device: Unpair-Post result: %s\n",
to_string(unpair_res).c_str());
}
}
}
}
}
static void removeDevice(std::shared_ptr<BTDevice> device) {
}
}
fprintf_td(stderr,
"****** Reset Adapter: reset[%d] start: %s\n", mode, a->
toString().c_str());
}
fprintf_td(stderr,
"****** Start discovery (%s) result: %s\n", msg.c_str(),
to_string(status).c_str());
}
static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) {
return false;
}
fprintf_td(stderr,
"Added to WHITELIST: res %d, address %s\n", res, it->toString().c_str());
}
} else {
return false;
}
}
return true;
}
if( added ) {
} else {
}
} else {
}
return true;
}
bool done = false;
fprintf_td(stderr,
"DirectBT Native Version %s (API %s)\n", DIRECT_BT_VERSION, DIRECT_BT_VERSION_API);
while( !done ) {
)
{
fprintf_td(stderr,
"****** EOL Test MULTI_MEASUREMENTS left %d, processed %zu/%zu\n",
done = true;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
}
fprintf_td(stderr,
"****** EOL Adapter's Devices - pre close: %s\n", adapter->
toString().c_str());
});
{
fprintf_td(stderr,
"****** EOL Removed ChangedAdapterSetCallback %d\n", count);
}
fprintf_td(stderr,
"****** EOL Adapter's Devices - post close: %s\n", adapter->
toString().c_str());
});
}
#include <cstdio>
int main(
int argc,
char *argv[])
{
bool waitForEnter=false;
for(int i=1; i<argc; i++) {
if( !strcmp("-dbt_debug", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.debug", argv[++i], 1 );
} else if( !strcmp("-dbt_verbose", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.verbose", argv[++i], 1 );
} else if( !strcmp("-dbt_gatt", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.gatt", argv[++i], 1 );
} else if( !strcmp("-dbt_l2cap", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.l2cap", argv[++i], 1 );
} else if( !strcmp("-dbt_hci", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.hci", argv[++i], 1 );
} else if( !strcmp("-dbt_mgmt", argv[i]) && argc > (i+1) ) {
setenv("direct_bt.mgmt", argv[++i], 1 );
} else if( !strcmp("-btmode", argv[i]) && argc > (i+1) ) {
setenv(
"direct_bt.mgmt.btmode",
to_string(btMode).c_str(), 1 );
}
} else if( !strcmp("-wait", argv[i]) ) {
waitForEnter = true;
} else if( !strcmp("-show_update_events", argv[i]) ) {
} else if( !strcmp("-quiet", argv[i]) ) {
} else if( !strcmp("-scanPassive", argv[i]) ) {
} else if( !strcmp("-dev", argv[i]) && argc > (i+1) ) {
std::string addrOrNameSub = std::string(argv[++i]);
} else if( !strcmp("-wl", argv[i]) && argc > (i+1) ) {
std::string macstr = std::string(argv[++i]);
fprintf(stderr, "Whitelist + %s\n", wle.toString().c_str());
} else if( !strcmp("-passkey", argv[i]) && argc > (i+2) ) {
const std::string addrOrNameSub(argv[++i]);
fprintf(stderr,
"Set passkey in %s\n", sec->
toString().c_str());
} else if( !strcmp("-seclevel", argv[i]) && argc > (i+2) ) {
const std::string addrOrNameSub(argv[++i]);
fprintf(stderr,
"Set sec_level in %s\n", sec->
toString().c_str());
} else if( !strcmp("-iocap", argv[i]) && argc > (i+2) ) {
const std::string addrOrNameSub(argv[++i]);
fprintf(stderr,
"Set io_cap in %s\n", sec->
toString().c_str());
} else if( !strcmp("-secauto", argv[i]) && argc > (i+2) ) {
const std::string addrOrNameSub(argv[++i]);
fprintf(stderr,
"Set SEC AUTO security io_cap in %s\n", sec->
toString().c_str());
} else if( !strcmp("-charid", argv[i]) && argc > (i+1) ) {
} else if( !strcmp("-charval", argv[i]) && argc > (i+1) ) {
} else if( !strcmp("-disconnect", argv[i]) ) {
} else if( !strcmp("-enableGATTPing", argv[i]) ) {
} else if( !strcmp("-keepDevice", argv[i]) ) {
} else if( !strcmp("-count", argv[i]) && argc > (i+1) ) {
} else if( !strcmp("-single", argv[i]) ) {
} else if( !strcmp("-resetEachCon", argv[i]) && argc > (i+1) ) {
}
}
fprintf(stderr, "pid %d\n", getpid());
fprintf(stderr, "Run with '[-btmode LE|BREDR|DUAL] "
"[-disconnect] [-enableGATTPing] [-count <number>] [-single] [-show_update_events] [-quiet] "
"[-scanPassive]"
"[-resetEachCon connectionCount] "
"(-dev <device_[address|name]_sub>)* (-wl <device_address>)* "
"(-seclevel <device_[address|name]_sub> <int_sec_level>)* "
"(-iocap <device_[address|name]_sub> <int_iocap>)* "
"(-secauto <device_[address|name]_sub> <int_iocap>)* "
"(-passkey <device_[address|name]_sub> <digits>)* "
"[-unpairPre] [-unpairPost] "
"[-charid <uuid>] [-charval <byte-val>] "
"[-dbt_verbose true|false] "
"[-dbt_debug true|false|adapter.event,gatt.data,hci.event,hci.scan_ad_eir,mgmt.event] "
"[-dbt_mgmt cmd.timeout=3000,ringsize=64,...] "
"[-dbt_hci cmd.complete.timeout=10000,cmd.status.timeout=3000,ringsize=64,...] "
"[-dbt_gatt cmd.read.timeout=500,cmd.write.timeout=500,cmd.init.timeout=2500,ringsize=128,...] "
"[-dbt_l2cap reader.timeout=10000,restart.count=0,...] "
"\n");
fprintf(stderr,
"QUIET %d\n",
QUIET);
fprintf(stderr,
"btmode %s\n",
to_string(btMode).c_str());
fprintf(stderr,
"characteristic-value: %d\n",
charValue);
if( waitForEnter ) {
fprintf(stderr, "Press ENTER to continue\n");
getchar();
}
fprintf(stderr, "****** TEST start\n");
fprintf(stderr, "****** TEST end\n");
if( true ) {
fprintf(stderr, "****** Manager close start\n");
fprintf(stderr, "****** Manager close end\n");
}
}