| 1 |
/* |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License version 2 as |
| 5 |
* published by the Free Software Foundation; |
| 6 |
* |
| 7 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 8 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 9 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 10 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| 11 |
* CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
* |
| 16 |
* ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 17 |
* COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| 18 |
* SOFTWARE IS DISCLAIMED. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
#include <config.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <unistd.h> |
| 29 |
#include <string.h> |
| 30 |
#include <signal.h> |
| 31 |
#include <fcntl.h> |
| 32 |
#include <errno.h> |
| 33 |
#include <ctype.h> |
| 34 |
#include <syslog.h> |
| 35 |
#include <stdarg.h> |
| 36 |
|
| 37 |
#include <termios.h> |
| 38 |
#include <fcntl.h> |
| 39 |
#include <getopt.h> |
| 40 |
#include <sys/types.h> |
| 41 |
#include <sys/ioctl.h> |
| •42 |
#include <sys/stat.h> |
| 43 |
|
| 44 |
#include <bluetooth/bluetooth.h> |
| 45 |
#include <bluetooth/hci.h> |
| 46 |
#include <bluetooth/hci_lib.h> |
| 47 |
|
| 48 |
#define DBUS_API_SUBJECT_TO_CHANGEcxx . . $ `bluetooth-monitor.c:48:9`! |
| 49 |
#include <dbus/dbus.h> |
| 50 |
#include <stdbool.h> |
| 51 |
#include <unistd.h> |
| 52 |
#include <stdio.h> |
| 53 |
#include <stdlib.h> |
| 54 |
|
| 55 |
#define BTCONNECTTIMEOUTcxx . . $ `bluetooth-monitor.c:55:9`! 5000 |
| 56 |
#define DEFAULTTHRESHOLDcxx . . $ `bluetooth-monitor.c:56:9`! 200 |
| 57 |
#define DEFAULTINTERVALcxx . . $ `bluetooth-monitor.c:57:9`! 100 |
| 58 |
//#define DEBUG |
| 59 |
|
| 60 |
#define DBUS_INTROSPECTION_DATAcxx . . $ `bluetooth-monitor.c:60:9`! "<!DOCTYPE node PUBLIC \ |
| 61 |
\"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" \ |
| 62 |
\"http://dbus.freedesktop.org/doc/introspect.dtd\"> \n\ |
| 63 |
<node name=\"/cx/ath/matthew/bluemon/Bluemon\">\n\ |
| 64 |
<interface name=\"cx.ath.matthew.bluemon.Bluemon\">\n\ |
| 65 |
<method name=\"Status\" >\n\ |
| 66 |
<arg name=\"address\" type=\"s\" direction=\"in\"/>\n\ |
| 67 |
<arg name=\"address\" type=\"s\" direction=\"out\"/>\n\ |
| 68 |
<arg name=\"status\" type=\"b\" direction=\"out\"/>\n\ |
| 69 |
<arg name=\"level\" type=\"u\" direction=\"out\"/>\n\ |
| 70 |
</method>\n\ |
| 71 |
</interface>\n\ |
| 72 |
<interface name=\"cx.ath.matthew.bluemon.ProximitySignal\">\n\ |
| 73 |
<signal name=\"Connect\" >\n\ |
| 74 |
<arg name=\"address\" type=\"s\" direction=\"out\"/>\n\ |
| 75 |
</signal>\n\ |
| 76 |
<signal name=\"Disconnect\" >\n\ |
| 77 |
<arg name=\"address\" type=\"s\" direction=\"out\"/>\n\ |
| 78 |
</signal>\n\ |
| 79 |
</interface>\n\ |
| 80 |
<interface name=\"org.freedesktop.DBus.Introspectable\">\n\ |
| 81 |
<method name=\"Introspect\">\n\ |
| 82 |
<arg type=\"s\" direction=\"out\"/>\n\ |
| 83 |
</method>\n\ |
| 84 |
</interface>\n\ |
| 85 |
</node>" |
| 86 |
|
| 87 |
|
| 88 |
struct devstructcxx . . $ devstruct#; |
| 89 |
typedef struct devstructcxx . . $ devstruct# { |
| 90 |
char* btidcxx . . $ devstruct#btid.; |
| 91 |
bdaddr_tcxx . . $ bdaddr_t# bdaddrcxx . . $ devstruct#bdaddr.; |
| 92 |
int ddcxx . . $ devstruct#dd.; |
| 93 |
int trackcxx . . $ devstruct#track.; |
| 94 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! connectedcxx . . $ devstruct#connected.; |
| 95 |
struct devstructcxx . . $ devstruct#* nextcxx . . $ devstruct#next.; |
| 96 |
} btdev_tcxx . . $ btdev_t#; |
| 97 |
|
| 98 |
btdev_tcxx . . $ btdev_t#* btdev_append_newcxx . . $ btdev_append_new(f58aabcdcf06f08).(btdev_tcxx . . $ btdev_t#* current, char* btid) |
| 99 |
{ |
| 100 |
btdev_tcxx . . $ btdev_t#* temp; |
| 101 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == current) { |
| 102 |
temp = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(btdev_tcxx . . $ btdev_t#)); |
| 103 |
temp->btidcxx . . $ devstruct#btid. = btid; |
| 104 |
temp->ddcxx . . $ devstruct#dd. = 0; |
| 105 |
temp->connectedcxx . . $ devstruct#connected. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 106 |
temp->nextcxx . . $ devstruct#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 107 |
temp->trackcxx . . $ devstruct#track. = -1; |
| 108 |
return temp; |
| 109 |
} |
| 110 |
else { |
| 111 |
current->nextcxx . . $ devstruct#next. = btdev_append_newcxx . . $ btdev_append_new(f58aabcdcf06f08).(current->nextcxx . . $ devstruct#next., btid); |
| 112 |
return current; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
typedef structcxx . . $ $anonymous_type_806a849bd12b9736_0# { |
| 117 |
char* configcxx . . $ $anonymous_type_806a849bd12b9736_0#config.; |
| 118 |
btdev_tcxx . . $ btdev_t#* btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot.; |
| 119 |
int thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold.; |
| 120 |
int intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval.; |
| 121 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 122 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork.; |
| 123 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose.; |
| 124 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate.; |
| 125 |
int uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid.; |
| 126 |
int gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid.; |
| 127 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! disconnecthackcxx . . $ $anonymous_type_806a849bd12b9736_0#disconnecthack.; |
| 128 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality.; |
| 129 |
} arg_tcxx . . $ arg_t#; |
| 130 |
arg_tcxx . . $ arg_t# optscxx . . $ opts.; |
| 131 |
arg_tcxx . . $ arg_t# argscxx . . $ args.; |
| 132 |
DBusConnectioncxx . . $ DBusConnection#* conncxx . . $ conn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 133 |
|
| 134 |
void messagecxx . . $ message(7505dec36442ba15).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! verbose, char* msg, ...); |
| 135 |
void sendsignalcxx . . $ sendsignal(9a78dea97370318a).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! connected, btdev_tcxx . . $ btdev_t#* btdev); |
| 136 |
|
| 137 |
#define assertcxx . . $ `bluetooth-monitor.c:137:9`!(a, b) if(!(a)) real_assert(b) |
| 138 |
void real_assertcxx . . $ real_assert(fda57c8427c60377). (char* msg) |
| 139 |
{ |
| 140 |
if (0 != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) { |
| 141 |
char* errstr = strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 142 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "[Assert] failed with errno %d/%s: %s\n", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, errstr, msg); |
| 143 |
} else |
| 144 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "[Assert] failed: %s\n", msg); |
| 145 |
#ifdef DEBUG |
| 146 |
exit(1); |
| 147 |
#endif |
| 148 |
} |
| 149 |
|
| 150 |
static int find_conncxx . . $ find_conn(bfd589b6ba05a0de).(int s, int dev_id, long arg) |
| 151 |
{ |
| 152 |
struct hci_conn_list_reqcxx . . $ hci_conn_list_req# *cl; |
| 153 |
struct hci_conn_infocxx . . $ hci_conn_info# *ci; |
| 154 |
int i; |
| 155 |
|
| 156 |
if (!(cl = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(10 * sizeof(*ci) + sizeof(*cl)))) { |
| 157 |
perrorcxx . . $ perror(85c52e162fed56f9).("Can't allocate memory"); |
| 158 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 159 |
} |
| 160 |
cl->dev_idcxx . . $ hci_conn_list_req#dev_id. = dev_id; |
| 161 |
cl->conn_numcxx . . $ hci_conn_list_req#conn_num. = 10; |
| 162 |
ci = cl->conn_infocxx . . $ hci_conn_list_req#conn_info.; |
| 163 |
|
| 164 |
if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(s, HCIGETCONNLISTcxx . . $ `<external>/7125456605024647188/hci.h:89:9`!, (void*)cl)) { |
| 165 |
perrorcxx . . $ perror(85c52e162fed56f9).("Can't get connection list"); |
| 166 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 167 |
} |
| 168 |
|
| 169 |
for (i=0; i < cl->conn_numcxx . . $ hci_conn_list_req#conn_num.; i++, ci++) |
| 170 |
if (!bacmpcxx . . $ bacmp(f4bbc3d289b99044).((bdaddr_tcxx . . $ bdaddr_t# *)arg, &ci->bdaddrcxx . . $ hci_conn_info#bdaddr.)) { |
| 171 |
freecxx . . $ free(5d22bdacc48458e8).(cl); |
| 172 |
return 1; |
| 173 |
} |
| 174 |
freecxx . . $ free(5d22bdacc48458e8).(cl); |
| 175 |
return 0; |
| 176 |
} |
| 177 |
|
| 178 |
// open connection |
| 179 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! btconnectcxx . . $ btconnect(5898bd06b6080674).(btdev_tcxx . . $ btdev_t#* btdev) |
| 180 |
{ |
| 181 |
int ptype; |
| 182 |
uint16_tcxx . . $ uint16_t# handle = 0; |
| 183 |
uint8_tcxx . . $ uint8_t# role; |
| 184 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! rval; |
| 185 |
struct hci_conn_info_reqcxx . . $ hci_conn_info_req# *cr; |
| 186 |
struct hci_requestcxx . . $ hci_request# rq; |
| 187 |
auth_requested_cpcxx . . $ auth_requested_cp# acp; |
| 188 |
evt_auth_completecxx . . $ evt_auth_complete# arp; |
| 189 |
evt_encrypt_changecxx . . $ evt_encrypt_change# erp; |
| 190 |
set_conn_encrypt_cpcxx . . $ set_conn_encrypt_cp# ecp; |
| 191 |
|
| 192 |
role = 0x01; |
| 193 |
ptype = HCI_DM1cxx . . $ `<external>/7125456605024647188/hci.h:121:9`! | HCI_DM3cxx . . $ `<external>/7125456605024647188/hci.h:125:9`! | HCI_DM5cxx . . $ `<external>/7125456605024647188/hci.h:129:9`! | HCI_DH1cxx . . $ `<external>/7125456605024647188/hci.h:122:9`! | HCI_DH3cxx . . $ `<external>/7125456605024647188/hci.h:126:9`! | HCI_DH5cxx . . $ `<external>/7125456605024647188/hci.h:130:9`!; |
| 194 |
|
| 195 |
int dev_id = hci_for_each_devcxx . . $ hci_for_each_dev(d8dadcc43b8de6d3).(HCI_UPcxx . . $ HCI_UP., find_conncxx . . $ find_conn(bfd589b6ba05a0de)., (long) &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 196 |
if (dev_id < 0) { |
| 197 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Connecting to: %x:%x:%x:%x:%x:%x\n", btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[5], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[4], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[3], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[2], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[1], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[0]); |
| 198 |
if (hci_create_connectioncxx . . $ hci_create_connection(dd33e1b954e93446).(btdev->ddcxx . . $ devstruct#dd., &(btdev->bdaddrcxx . . $ devstruct#bdaddr.), htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(ptype), 0, role, &handle, BTCONNECTTIMEOUTcxx . . $ `bluetooth-monitor.c:55:9`!) < 0) { |
| 199 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Can't create connection\n"); |
| 200 |
return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 201 |
} |
| 202 |
btdev->connectedcxx . . $ devstruct#connected. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 203 |
} |
| 204 |
else btdev->connectedcxx . . $ devstruct#connected. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 205 |
|
| 206 |
if (0 == handle) { |
| 207 |
cr = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*cr) + sizeof(struct hci_conn_infocxx . . $ hci_conn_info#)); |
| 208 |
|
| 209 |
bacpycxx . . $ bacpy(d313a890a91d3440).(&cr->bdaddrcxx . . $ hci_conn_info_req#bdaddr., &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 210 |
cr->typecxx . . $ hci_conn_info_req#type. = ACL_LINKcxx . . $ `<external>/7125456605024647188/hci.h:211:9`!; |
| 211 |
if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(btdev->ddcxx . . $ devstruct#dd., HCIGETCONNINFOcxx . . $ `<external>/7125456605024647188/hci.h:90:9`!, (unsigned long) cr) < 0) { |
| 212 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Get connection info failed"); |
| 213 |
return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 214 |
} |
| 215 |
handle = htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(cr->conn_info->handle); |
| 216 |
freecxx . . $ free(5d22bdacc48458e8).(cr); |
| 217 |
} |
| 218 |
|
| 219 |
if (optscxx . . $ opts..authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate. || argscxx . . $ args..authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate.) { |
| 220 |
|
| 221 |
acp.handlecxx . . $ $anonymous_type_9cde43c605026bd2_14#handle. = htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(handle); |
| 222 |
|
| 223 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).(&rq, 0, sizeof(rq)); |
| 224 |
rq.ogfcxx . . $ hci_request#ogf. = OGF_LINK_CTLcxx . . $ `<external>/7125456605024647188/hci.h:309:9`!; |
| 225 |
rq.ocfcxx . . $ hci_request#ocf. = OCF_AUTH_REQUESTEDcxx . . $ `<external>/7125456605024647188/hci.h:410:9`!; |
| 226 |
rq.cparamcxx . . $ hci_request#cparam. = &acp; |
| 227 |
rq.clencxx . . $ hci_request#clen. = AUTH_REQUESTED_CP_SIZEcxx . . $ `<external>/7125456605024647188/hci.h:414:9`!; |
| 228 |
rq.rparamcxx . . $ hci_request#rparam. = &arp; |
| 229 |
rq.rlencxx . . $ hci_request#rlen. = EVT_AUTH_COMPLETE_SIZEcxx . . $ `<external>/7125456605024647188/hci.h:1787:9`!; |
| 230 |
rq.eventcxx . . $ hci_request#event. = EVT_AUTH_COMPLETEcxx . . $ `<external>/7125456605024647188/hci.h:1782:9`!; |
| 231 |
|
| 232 |
if (hci_send_reqcxx . . $ hci_send_req(d55064a7c6c87de6).(btdev->ddcxx . . $ devstruct#dd., &rq, 25000) < 0) { |
| 233 |
#ifdef DEBUG |
| 234 |
message(true, "Can't authenticate link\n"); |
| 235 |
#endif |
| 236 |
return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 237 |
} |
| 238 |
ecp.handlecxx . . $ $anonymous_type_9cde43c605026bd2_15#handle. = htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(handle); |
| 239 |
ecp.encryptcxx . . $ $anonymous_type_9cde43c605026bd2_15#encrypt. = 1; |
| 240 |
|
| 241 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).(&rq, 0, sizeof(rq)); |
| 242 |
rq.ogfcxx . . $ hci_request#ogf. = OGF_LINK_CTLcxx . . $ `<external>/7125456605024647188/hci.h:309:9`!; |
| 243 |
rq.ocfcxx . . $ hci_request#ocf. = OCF_SET_CONN_ENCRYPTcxx . . $ `<external>/7125456605024647188/hci.h:416:9`!; |
| 244 |
rq.cparamcxx . . $ hci_request#cparam. = &ecp; |
| 245 |
rq.clencxx . . $ hci_request#clen. = SET_CONN_ENCRYPT_CP_SIZEcxx . . $ `<external>/7125456605024647188/hci.h:421:9`!; |
| 246 |
rq.rparamcxx . . $ hci_request#rparam. = &erp; |
| 247 |
rq.rlencxx . . $ hci_request#rlen. = EVT_ENCRYPT_CHANGE_SIZEcxx . . $ `<external>/7125456605024647188/hci.h:1803:9`!; |
| 248 |
rq.eventcxx . . $ hci_request#event. = EVT_ENCRYPT_CHANGEcxx . . $ `<external>/7125456605024647188/hci.h:1797:9`!; |
| 249 |
|
| 250 |
if (hci_send_reqcxx . . $ hci_send_req(d55064a7c6c87de6).(btdev->ddcxx . . $ devstruct#dd., &rq, 25000) < 0) { |
| 251 |
#ifdef DEBUG |
| 252 |
message(true, "Can't encrypt link\n"); |
| 253 |
#endif |
| 254 |
return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 255 |
} |
| 256 |
} |
| 257 |
return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
// close connection |
| 262 |
void btdisconnectcxx . . $ btdisconnect(4614daf50ac1d508).(btdev_tcxx . . $ btdev_t#* btdev) |
| 263 |
{ |
| 264 |
struct hci_conn_info_reqcxx . . $ hci_conn_info_req# *cr; |
| 265 |
cr = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*cr) + sizeof(struct hci_conn_infocxx . . $ hci_conn_info#)); |
| 266 |
if (!cr) |
| 267 |
return; |
| 268 |
|
| 269 |
bacpycxx . . $ bacpy(d313a890a91d3440).(&cr->bdaddrcxx . . $ hci_conn_info_req#bdaddr., &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 270 |
cr->typecxx . . $ hci_conn_info_req#type. = ACL_LINKcxx . . $ `<external>/7125456605024647188/hci.h:211:9`!; |
| 271 |
if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(btdev->ddcxx . . $ devstruct#dd., HCIGETCONNINFOcxx . . $ `<external>/7125456605024647188/hci.h:90:9`!, (unsigned long) cr) < 0) { |
| 272 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Get connection info failed\n"); |
| 273 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 274 |
} |
| 275 |
|
| 276 |
if (hci_disconnectcxx . . $ hci_disconnect(a2b3a94cd0381a6c).(btdev->ddcxx . . $ devstruct#dd., htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(cr->conn_info->handle), HCI_OE_USER_ENDED_CONNECTIONcxx . . $ `<external>/7125456605024647188/hci.h:166:9`!, 100) < 0) |
| 277 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Disconnect failed\n"); |
| 278 |
freecxx . . $ free(5d22bdacc48458e8).(cr); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
// query link quality |
| 284 |
int get_link_qualcxx . . $ get_link_qual(fd4f959995dcc4eb).(btdev_tcxx . . $ btdev_t#* btdev) |
| 285 |
{ |
| 286 |
struct hci_conn_info_reqcxx . . $ hci_conn_info_req# *cr; |
| 287 |
struct hci_requestcxx . . $ hci_request# rq; |
| 288 |
#ifdef OCF_GET_LINK_QUALITY |
| 289 |
get_link_quality_rp rp; |
| 290 |
#else |
| 291 |
read_link_quality_rpcxx . . $ read_link_quality_rp# rp; |
| 292 |
#endif |
| 293 |
uint16_tcxx . . $ uint16_t# handle; |
| 294 |
int qual; |
| 295 |
|
| 296 |
// check the quality |
| 297 |
if (optscxx . . $ opts..linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality. || argscxx . . $ args..linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality.) { |
| 298 |
cr = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*cr) + sizeof(struct hci_conn_infocxx . . $ hci_conn_info#)); |
| 299 |
if (!cr) |
| •300 |
return 0; |
| 301 |
bacpycxx . . $ bacpy(d313a890a91d3440).(&cr->bdaddrcxx . . $ hci_conn_info_req#bdaddr., &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 302 |
cr->typecxx . . $ hci_conn_info_req#type. = ACL_LINKcxx . . $ `<external>/7125456605024647188/hci.h:211:9`!; |
| 303 |
if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(btdev->ddcxx . . $ devstruct#dd., HCIGETCONNINFOcxx . . $ `<external>/7125456605024647188/hci.h:90:9`!, (unsigned long) cr) < 0) { |
| 304 |
#ifdef DEBUG |
| 305 |
message(true, "Get connection info failed, trying reconnect\n"); |
| 306 |
#endif |
| 307 |
return -1; |
| 308 |
} |
| 309 |
|
| 310 |
handle = htobscxx . . $ `<external>/9464720282304091114/bluetooth.h:262:9`!(cr->conn_info->handle); |
| 311 |
|
| 312 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).(&rq, 0, sizeof(rq)); |
| 313 |
rq.ogfcxx . . $ hci_request#ogf. = OGF_STATUS_PARAMcxx . . $ `<external>/7125456605024647188/hci.h:1343:9`!; |
| 314 |
#ifdef OCF_GET_LINK_QUALITY |
| 315 |
rq.ocf = OCF_GET_LINK_QUALITY; |
| 316 |
#else |
| 317 |
rq.ocfcxx . . $ hci_request#ocf. = OCF_READ_LINK_QUALITYcxx . . $ `<external>/7125456605024647188/hci.h:1360:9`!; |
| 318 |
#endif |
| 319 |
rq.cparamcxx . . $ hci_request#cparam. = &handle; |
| 320 |
rq.clencxx . . $ hci_request#clen. = 2; |
| 321 |
rq.rparamcxx . . $ hci_request#rparam. = &rp; |
| 322 |
#ifdef OCF_GET_LINK_QUALITY_RP_SIZE |
| 323 |
rq.rlen = GET_LINK_QUALITY_RP_SIZE; |
| 324 |
#else |
| 325 |
rq.rlencxx . . $ hci_request#rlen. = READ_LINK_QUALITY_RP_SIZEcxx . . $ `<external>/7125456605024647188/hci.h:1366:9`!; |
| 326 |
#endif |
| 327 |
|
| 328 |
if (hci_send_reqcxx . . $ hci_send_req(d55064a7c6c87de6).(btdev->ddcxx . . $ devstruct#dd., &rq, 100) < 0) { |
| 329 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "HCI get_link_quality request failed, trying reconnect\n"); |
| 330 |
freecxx . . $ free(5d22bdacc48458e8).(cr); |
| 331 |
return -1; |
| 332 |
} |
| 333 |
|
| 334 |
if (rp.statuscxx . . $ $anonymous_type_9cde43c605026bd2_136#status.) { |
| 335 |
#ifdef DEBUG |
| 336 |
message(true, "HCI get_link_quality cmd failed (0x%2.2X), trying reconnect\n", rp.status); |
| 337 |
#endif |
| 338 |
freecxx . . $ free(5d22bdacc48458e8).(cr); |
| 339 |
return -1; |
| 340 |
} |
| 341 |
|
| 342 |
qual = rp.link_qualitycxx . . $ $anonymous_type_9cde43c605026bd2_136#link_quality.; |
| 343 |
freecxx . . $ free(5d22bdacc48458e8).(cr); |
| 344 |
return qual; |
| 345 |
} |
| 346 |
// just check for connection |
| 347 |
else { |
| 348 |
qual = hci_for_each_devcxx . . $ hci_for_each_dev(d8dadcc43b8de6d3).(HCI_UPcxx . . $ HCI_UP., find_conncxx . . $ find_conn(bfd589b6ba05a0de)., (long) &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 349 |
return qual < 0 ? qual : 255; |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
void readoptionscxx . . $ readoptions(a89cbe03bdfdbb3f).(arg_tcxx . . $ arg_t# args, arg_tcxx . . $ arg_t#* opts) |
| 354 |
{ |
| 355 |
opts->configcxx . . $ $anonymous_type_806a849bd12b9736_0#config. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 356 |
opts->btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 357 |
opts->thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold. = DEFAULTTHRESHOLDcxx . . $ `bluetooth-monitor.c:56:9`!; |
| 358 |
opts->intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval. = DEFAULTINTERVALcxx . . $ `bluetooth-monitor.c:57:9`!; |
| 359 |
opts->stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 360 |
opts->forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 361 |
opts->verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 362 |
opts->uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid. = 0; |
| 363 |
opts->gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid. = 0; |
| 364 |
opts->authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 365 |
opts->linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 366 |
} |
| 367 |
|
| 368 |
char* prognamecxx . . $ progname.; |
| 369 |
|
| 370 |
void syntaxcxx . . $ syntax(d878ad36e69247c7).() |
| 371 |
{ |
| 372 |
printfcxx . . $ printf(581fddd72a8db8fc).("Syntax: %s <options>\n", prognamecxx . . $ progname.); |
| 373 |
//printf(" -c configfile --config=configfile\n"); |
| 374 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -b aa:bb:cc:dd:ee:ff --btid=aa:bb:cc:dd:ee:ff\n"); |
| 375 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -t threshold --threshold=threshold\n"); |
| 376 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -i interval --interval=interval\n"); |
| 377 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -s --stdout --no-syslog\n"); |
| 378 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -n --no-fork\n"); |
| 379 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -v --verbose\n"); |
| 380 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -V --version\n"); |
| 381 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -d --disconnect-hack\n"); |
| 382 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -q --link-quality\n"); |
| 383 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -a --authenticate\n"); |
| 384 |
printfcxx . . $ printf(581fddd72a8db8fc).(" -h --help\n"); |
| 385 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 386 |
} |
| 387 |
|
| 388 |
/* |
| 389 |
* -c --config |
| 390 |
* -b --btid |
| 391 |
* -t --threshold |
| 392 |
* -i --interval |
| 393 |
* -s --stdout --no-syslog |
| 394 |
* -n --no-fork |
| 395 |
* -v --verbose |
| 396 |
* -a --authenticate |
| 397 |
* -h --help |
| 398 |
*/ |
| 399 |
void readargscxx . . $ readargs(471275268b68909b).(int argc, char** argv, arg_tcxx . . $ arg_t#* args) |
| 400 |
{ |
| 401 |
args->configcxx . . $ $anonymous_type_806a849bd12b9736_0#config. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 402 |
args->btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 403 |
args->thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold. = DEFAULTTHRESHOLDcxx . . $ `bluetooth-monitor.c:56:9`!; |
| 404 |
args->intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval. = DEFAULTINTERVALcxx . . $ `bluetooth-monitor.c:57:9`!; |
| 405 |
args->stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 406 |
args->forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 407 |
args->verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 408 |
args->authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 409 |
args->disconnecthackcxx . . $ $anonymous_type_806a849bd12b9736_0#disconnecthack. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 410 |
args->linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 411 |
args->uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid. = 0; |
| 412 |
args->gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid. = 0; |
| 413 |
|
| 414 |
int c; |
| 415 |
static struct optioncxx . . $ option# long_opts[] = { |
| 416 |
{"config", 1, 0, 'c'}, |
| 417 |
{"btid", 1, 0, 'b'}, |
| 418 |
{"threshold", 1, 0, 't'}, |
| 419 |
{"interval", 1, 0, 'i'}, |
| 420 |
{"stdout", 0, 0, 's'}, |
| 421 |
{"help", 0, 0, 'h'}, |
| 422 |
{"no-fork", 0, 0, 'n'}, |
| 423 |
{"verbose", 0, 0, 'v'}, |
| 424 |
{"version", 0, 0, 'V'}, |
| 425 |
{"authenticate", 0, 0, 'a'}, |
| 426 |
{"no-syslog", 0, 0, 's'}, |
| 427 |
{"uid", 1, 0, 'u'}, |
| 428 |
{"gid", 1, 0, 'u'}, |
| 429 |
{"disconnect-hack", 1, 0, 'd'}, |
| 430 |
{"link-quality", 1, 0, 'q'} |
| 431 |
}; |
| 432 |
int idx = 0; |
| 433 |
while (-1 != (c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "-c:b:t:i:o:sqhVndvag:u:",long_opts, &idx))) { |
| 434 |
switch (c) { |
| 435 |
case 'c': |
| 436 |
args->configcxx . . $ $anonymous_type_806a849bd12b9736_0#config. = optargcxx . . $ optarg.; |
| 437 |
break; |
| 438 |
case 'b': |
| 439 |
args->btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot. = btdev_append_newcxx . . $ btdev_append_new(f58aabcdcf06f08).(args->btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optargcxx . . $ optarg.); |
| 440 |
break; |
| 441 |
case 't': |
| 442 |
args->thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 443 |
break; |
| 444 |
case 'i': |
| 445 |
args->intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 446 |
break; |
| 447 |
case 'u': |
| 448 |
args->uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 449 |
break; |
| 450 |
case 'g': |
| 451 |
args->gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 452 |
break; |
| 453 |
case 's': |
| 454 |
args->stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 455 |
break; |
| 456 |
case 'n': |
| 457 |
args->forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 458 |
break; |
| 459 |
case 'v': |
| 460 |
args->verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 461 |
break; |
| 462 |
case 'd': |
| 463 |
args->disconnecthackcxx . . $ $anonymous_type_806a849bd12b9736_0#disconnecthack. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 464 |
break; |
| 465 |
case 'a': |
| 466 |
args->authenticatecxx . . $ $anonymous_type_806a849bd12b9736_0#authenticate. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 467 |
break; |
| 468 |
case 'q': |
| 469 |
args->linkqualitycxx . . $ $anonymous_type_806a849bd12b9736_0#linkquality. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 470 |
break; |
| 471 |
case 'V': |
| 472 |
printfcxx . . $ printf(581fddd72a8db8fc).("Bluemon version %s.\n", VERSIONcxx . . $ `<built-in>:412:9`!); |
| 473 |
break; |
| 474 |
case 'h': |
| 475 |
case ':': |
| 476 |
case '?': |
| 477 |
case 1: |
| 478 |
syntaxcxx . . $ syntax(d878ad36e69247c7).(); |
| 479 |
break; |
| 480 |
} |
| 481 |
idx = 0; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
int testintcxx . . $ testint(56759362374d8228).(int a, int b, char* errormsg) |
| 486 |
{ |
| 487 |
if (0 != a) |
| 488 |
return a; |
| 489 |
if (0 != b) |
| 490 |
return b; |
| 491 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "%s\n", errormsg); |
| 492 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 493 |
} |
| 494 |
btdev_tcxx . . $ btdev_t#* testdevcxx . . $ testdev(2d65428583a747ef).(btdev_tcxx . . $ btdev_t#* a, btdev_tcxx . . $ btdev_t#* b, char* errormsg) |
| 495 |
{ |
| 496 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != a) |
| 497 |
return a; |
| 498 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != b) |
| 499 |
return b; |
| 500 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "%s\n", errormsg); |
| 501 |
|
| 502 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 503 |
} |
| 504 |
char* testcharcxx . . $ testchar(a1df38fec57fccd9).(char* a, char* b, char* errormsg) |
| 505 |
{ |
| 506 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != a) |
| 507 |
return a; |
| 508 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != b) |
| 509 |
return b; |
| 510 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "%s\n", errormsg); |
| 511 |
|
| 512 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 513 |
} |
| 514 |
|
| 515 |
// write a message to syslog or stdout depending on setup |
| 516 |
void messagecxx . . $ message(7505dec36442ba15).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! verbose, char* msg, ...) |
| 517 |
{ |
| 518 |
if (!argscxx . . $ args..verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose. && !optscxx . . $ opts..verbosecxx . . $ $anonymous_type_806a849bd12b9736_0#verbose. && verbose) return; |
| 519 |
va_listcxx . . $ va_list# vargs; |
| 520 |
va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(vargs, msg); |
| 521 |
|
| 522 |
if (argscxx . . $ args..stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! || optscxx . . $ opts..stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) |
| 523 |
vprintfcxx . . $ vprintf(5c80dbd47e6ebfbb).(msg, vargs); |
| 524 |
else |
| 525 |
vsyslogcxx . . $ vsyslog(7aa579bceef62d01).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, msg, vargs); |
| 526 |
|
| 527 |
va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(vargs); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
void sighandlecxx . . $ sighandle(d4f767463ce0a6b3).(int signum) |
| 533 |
{ |
| 534 |
btdev_tcxx . . $ btdev_t#* btdev; |
| 535 |
switch (signum) { |
| 536 |
case SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!: |
| 537 |
case SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!: |
| 538 |
btdev = testdevcxx . . $ testdev(2d65428583a747ef).(argscxx . . $ args..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optscxx . . $ opts..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., "No Devices Specified"); |
| 539 |
while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != btdev) { |
| 540 |
if (btdev->connectedcxx . . $ devstruct#connected.) { |
| 541 |
// disconnect bluetooth |
| 542 |
btdisconnectcxx . . $ btdisconnect(4614daf50ac1d508).(btdev); |
| 543 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Disconnected %s\n", btdev->btidcxx . . $ devstruct#btid.); |
| 544 |
} |
| 545 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != conncxx . . $ conn.) |
| 546 |
sendsignalcxx . . $ sendsignal(9a78dea97370318a).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, btdev); |
| 547 |
hci_close_devcxx . . $ hci_close_dev(7864480464b09eea).(btdev->ddcxx . . $ devstruct#dd.); |
| 548 |
btdev_tcxx . . $ btdev_t#* temp = btdev->nextcxx . . $ devstruct#next.; |
| 549 |
freecxx . . $ free(5d22bdacc48458e8).(btdev); |
| 550 |
btdev = temp; |
| 551 |
} |
| 552 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Caught SIGTERM, announcing our demise\n"); |
| 553 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != conncxx . . $ conn.) |
| 554 |
dbus_connection_unrefcxx . . $ dbus_connection_unref(5ffe6e60e141c747).(conncxx . . $ conn.); |
| 555 |
exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 556 |
case SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!: |
| 557 |
readoptionscxx . . $ readoptions(a89cbe03bdfdbb3f).(argscxx . . $ args., &optscxx . . $ opts.); |
| 558 |
break; |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
void writepidfilecxx . . $ writepidfile(49f6e7a06ebc5aa8).(void) |
| 563 |
{ |
| 564 |
FILEcxx . . $ FILE#* fd; |
| 565 |
fd = fopencxx . . $ fopen(82ec0787cd37e0a3).("/var/run/bluemon.pid", "w"); |
| 566 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != fd) { |
| 567 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fd, "%d", getpidcxx . . $ getpid(b126dc7c1de90089).()); |
| 568 |
fclosecxx . . $ fclose(89bc1efcdac0ca22).(fd); |
| 569 |
} else { |
| 570 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Could not write PID file, quitting\n"); |
| 571 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
DBusConnectioncxx . . $ DBusConnection#* register_dbuscxx . . $ register_dbus(24dc0d38ee6e2321).() |
| 576 |
{ |
| 577 |
DBusErrorcxx . . $ DBusError# err; |
| 578 |
DBusConnectioncxx . . $ DBusConnection#* conn; |
| 579 |
int ret; |
| 580 |
|
| 581 |
dbus_error_initcxx . . $ dbus_error_init(b79b632916b634d5).(&err); |
| 582 |
|
| 583 |
conn = dbus_bus_getcxx . . $ dbus_bus_get(55765b610750c92d).(DBUS_BUS_SYSTEMcxx . . $ DBUS_BUS_SYSTEM., &err); |
| 584 |
if (dbus_error_is_setcxx . . $ dbus_error_is_set(bfe7bc821936b44).(&err)) { |
| 585 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "DBUS Connection Error (%s)\n", err.messagecxx . . $ DBusError#message.); |
| 586 |
dbus_error_freecxx . . $ dbus_error_free(b79b632916b634d5).(&err); |
| 587 |
} |
| 588 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == conn) { |
| 589 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 590 |
} |
| 591 |
|
| 592 |
ret = dbus_bus_request_namecxx . . $ dbus_bus_request_name(92ac60329a3c14d4).(conn, "cx.ath.matthew.bluemon.server", |
| 593 |
DBUS_NAME_FLAG_REPLACE_EXISTINGcxx . . $ `<external>/10384850255631450945/dbus-shared.h:111:9`!, |
| 594 |
&err); |
| 595 |
if (dbus_error_is_setcxx . . $ dbus_error_is_set(bfe7bc821936b44).(&err)) { |
| 596 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "DBUS Name Error (%s)\n", err.messagecxx . . $ DBusError#message.); |
| 597 |
dbus_error_freecxx . . $ dbus_error_free(b79b632916b634d5).(&err); |
| 598 |
} |
| 599 |
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNERcxx . . $ `<external>/10384850255631450945/dbus-shared.h:115:9`! != ret) { |
| 600 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 601 |
} |
| 602 |
return conn; |
| 603 |
} |
| 604 |
|
| 605 |
void sendsignalcxx . . $ sendsignal(9a78dea97370318a).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! inrange, btdev_tcxx . . $ btdev_t#* btdev) |
| 606 |
{ |
| 607 |
DBusMessagecxx . . $ DBusMessage#* msg; |
| 608 |
DBusMessageItercxx . . $ DBusMessageIter# it; |
| 609 |
dbus_uint32_tcxx . . $ dbus_uint32_t# serial; |
| 610 |
if (inrange) |
| 611 |
msg = dbus_message_new_signalcxx . . $ dbus_message_new_signal(e69f6a47e9ecc411).("/cx/ath/matthew/bluemon/Bluemon", "cx.ath.matthew.bluemon.ProximitySignal", "Connect"); |
| 612 |
else |
| 613 |
msg = dbus_message_new_signalcxx . . $ dbus_message_new_signal(e69f6a47e9ecc411).("/cx/ath/matthew/bluemon/Bluemon", "cx.ath.matthew.bluemon.ProximitySignal", "Disconnect"); |
| 614 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == msg) { messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "DBUS Message Null, ALIEN INVASION\n"); exitcxx . . $ exit(3ca292c338df9bb3).(1); } |
| 615 |
dbus_message_iter_init_appendcxx . . $ dbus_message_iter_init_append(bdfd43ed78e92566).(msg, &it); |
| 616 |
if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!, &(btdev->btidcxx . . $ devstruct#btid.))) { |
| 617 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory!"); |
| 618 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 619 |
} |
| 620 |
if (!dbus_connection_sendcxx . . $ dbus_connection_send(83479337446ba1bb).(conncxx . . $ conn., msg, &serial)) { |
| 621 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory!"); |
| 622 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 623 |
} |
| 624 |
|
| 625 |
//dbus_connection_flush(conn); |
| 626 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); |
| 627 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Signal sent (%s, %s)\n", inrange?"true":"false", btdev->btidcxx . . $ devstruct#btid.); |
| 628 |
} |
| 629 |
|
| 630 |
void handle_dbus_messagecxx . . $ handle_dbus_message(51fb7f56b8b56ff7).(DBusMessagecxx . . $ DBusMessage#* msg, int threshold) |
| 631 |
{ |
| 632 |
DBusMessagecxx . . $ DBusMessage#* reply; |
| 633 |
DBusMessageItercxx . . $ DBusMessageIter# it; |
| 634 |
dbus_uint32_tcxx . . $ dbus_uint32_t# serial, level; |
| 635 |
dbus_bool_tcxx . . $ dbus_bool_t# stat; |
| 636 |
char* address; |
| 637 |
|
| 638 |
if (!dbus_message_iter_initcxx . . $ dbus_message_iter_init(ffe71547a19cf1fb).(msg, &it)) { |
| 639 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Bad parameter count for Status message"); |
| 640 |
return; |
| 641 |
} |
| 642 |
if (DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`! != dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&it)) { |
| 643 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Bad parameter type (%d) for Status message", dbus_message_iter_get_arg_typecxx . . $ dbus_message_iter_get_arg_type(f50db427ad27749a).(&it)); |
| 644 |
return; |
| 645 |
} |
| 646 |
dbus_message_iter_get_basiccxx . . $ dbus_message_iter_get_basic(5a06ffdfd9031a8).(&it, &address); |
| 647 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Handling dbus status query for %d\n", address); |
| 648 |
reply = dbus_message_new_method_returncxx . . $ dbus_message_new_method_return(4b02851a30b507b9).(msg); |
| 649 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == reply) { |
| 650 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Reply is NULL!! You have been eaten by a GRUE!"); |
| 651 |
return; |
| 652 |
} |
| 653 |
dbus_message_iter_init_appendcxx . . $ dbus_message_iter_init_append(bdfd43ed78e92566).(reply, &it); |
| 654 |
btdev_tcxx . . $ btdev_t#* btdev = testdevcxx . . $ testdev(2d65428583a747ef).(argscxx . . $ args..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optscxx . . $ opts..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., "No Devices Specified"); |
| 655 |
for (; NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != btdev; btdev = btdev->nextcxx . . $ devstruct#next.) { |
| 656 |
if (0 == strncmpcxx . . $ strncmp(fd278af2f295fa2e).("", address, 1) || 0 == strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(btdev->btidcxx . . $ devstruct#btid., address, strlencxx . . $ strlen(751346f8406fd082).(btdev->btidcxx . . $ devstruct#btid.))) { |
| 657 |
if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!, &(btdev->btidcxx . . $ devstruct#btid.))) { |
| 658 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! Lock me in the cellar and feed me pins, PINS!!"); |
| 659 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 660 |
return; |
| 661 |
} |
| 662 |
if (btdev->trackcxx . . $ devstruct#track. >= threshold) { |
| 663 |
stat = TRUEcxx . . $ `<external>/9014550081379089389/dbus-macros.h:41:11`!; |
| 664 |
level = btdev->trackcxx . . $ devstruct#track.; |
| 665 |
} else { |
| 666 |
stat = FALSEcxx . . $ `<external>/9014550081379089389/dbus-macros.h:44:11`!; |
| 667 |
level = -1; |
| 668 |
} |
| 669 |
break; |
| 670 |
} else { |
| 671 |
//address = ""; |
| 672 |
stat = FALSEcxx . . $ `<external>/9014550081379089389/dbus-macros.h:44:11`!; |
| 673 |
level = -1; |
| 674 |
dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!, &address); |
| 675 |
} |
| 676 |
} |
| 677 |
if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_BOOLEANcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:72:9`!, &stat)){ |
| 678 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! The bells! the bells!"); |
| 679 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 680 |
return; |
| 681 |
} |
| 682 |
|
| 683 |
if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_UINT32cxx . . $ `<external>/9999628393408380398/dbus-protocol.h:88:9`!, &level)){ |
| 684 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! Every night the steam part of my brain and feed it to their mum!"); |
| 685 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 686 |
return; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
if (!dbus_connection_sendcxx . . $ dbus_connection_send(83479337446ba1bb).(conncxx . . $ conn., reply, &serial)){ |
| 691 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! Universe error, redo from start!"); |
| 692 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 693 |
return; |
| 694 |
} |
| 695 |
dbus_connection_flushcxx . . $ dbus_connection_flush(5ffe6e60e141c747).(conncxx . . $ conn.); |
| 696 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
void handle_introspection_messagecxx . . $ handle_introspection_message(ef6f40ad6aaa7be8).(DBusMessagecxx . . $ DBusMessage#* msg) |
| 701 |
{ |
| 702 |
DBusMessagecxx . . $ DBusMessage#* reply; |
| 703 |
DBusMessageItercxx . . $ DBusMessageIter# it; |
| 704 |
dbus_uint32_tcxx . . $ dbus_uint32_t# serial; |
| 705 |
char* xml = DBUS_INTROSPECTION_DATAcxx . . $ `bluetooth-monitor.c:60:9`!; |
| 706 |
|
| 707 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Handling dbus introspection query\n"); |
| 708 |
reply = dbus_message_new_method_returncxx . . $ dbus_message_new_method_return(4b02851a30b507b9).(msg); |
| 709 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == reply) { |
| 710 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Reply is NULL!! You have been eaten by a GRUE!"); |
| 711 |
return; |
| 712 |
} |
| 713 |
dbus_message_iter_init_appendcxx . . $ dbus_message_iter_init_append(bdfd43ed78e92566).(reply, &it); |
| 714 |
if (!dbus_message_iter_append_basiccxx . . $ dbus_message_iter_append_basic(dea9ad080b919705).(&it, DBUS_TYPE_STRINGcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:104:9`!, &xml)){ |
| 715 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! The bells! the bells!"); |
| 716 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 717 |
return; |
| 718 |
} |
| 719 |
|
| 720 |
if (!dbus_connection_sendcxx . . $ dbus_connection_send(83479337446ba1bb).(conncxx . . $ conn., reply, &serial)){ |
| 721 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Out Of Memory! Universe error, redo from start!"); |
| 722 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 723 |
return; |
| 724 |
} |
| 725 |
dbus_connection_flushcxx . . $ dbus_connection_flush(5ffe6e60e141c747).(conncxx . . $ conn.); |
| 726 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(reply); |
| 727 |
} |
| 728 |
|
| 729 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc, char ** argv) |
| 730 |
{ |
| 731 |
int dev_id, pid; |
| 732 |
int track, threshold, interval; |
| 733 |
char* btid; |
| 734 |
int ret; |
| 735 |
int lq = 0; |
| 736 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! run = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 737 |
boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! foo = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 738 |
DBusMessagecxx . . $ DBusMessage#* msg; |
| 739 |
DBusMessagecxx . . $ DBusMessage#* err; |
| 740 |
dbus_uint32_tcxx . . $ dbus_uint32_t# serial; |
| 741 |
|
| 742 |
prognamecxx . . $ progname. = argv[0]; |
| 743 |
|
| 744 |
readargscxx . . $ readargs(471275268b68909b).(argc, argv, &argscxx . . $ args.); |
| 745 |
readoptionscxx . . $ readoptions(a89cbe03bdfdbb3f).(argscxx . . $ args., &optscxx . . $ opts.); |
| 746 |
|
| 747 |
// fork |
| 748 |
if (argscxx . . $ args..forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork. && optscxx . . $ opts..forkcxx . . $ $anonymous_type_806a849bd12b9736_0#fork.) { |
| 749 |
pid = forkcxx . . $ fork(b126dc7c1de90089).(); |
| 750 |
if (pid < 0) |
| 751 |
printfcxx . . $ printf(581fddd72a8db8fc).("Cannot fork"); |
| 752 |
if (pid > 0) |
| 753 |
exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 754 |
else { |
| 755 |
setsidcxx . . $ setsid(b126dc7c1de90089).(); |
| 756 |
chdircxx . . $ chdir(5c4306d8553b3696).("/"); |
| 757 |
umaskcxx . . $ umask(2141b656ce2cc063).(0); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
writepidfilecxx . . $ writepidfile(49f6e7a06ebc5aa8).(); |
| 762 |
|
| 763 |
// syslog |
| 764 |
if (!(argscxx . . $ args..stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! || optscxx . . $ opts..stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!)) |
| 765 |
openlogcxx . . $ openlog(7b85637613228108).("bluetooth-monitor",0, LOG_DAEMONcxx . . $ `<external>/6168640806541382331/syslog.h:96:9`!); |
| 766 |
|
| 767 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Bluetooth monitoring system startup, version %s\n", VERSIONcxx . . $ `<built-in>:412:9`!); |
| 768 |
|
| 769 |
// register cleanup code |
| 770 |
signalcxx . . $ signal(c2d516773f91faf8).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, sighandlecxx . . $ sighandle(d4f767463ce0a6b3).); |
| 771 |
signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, sighandlecxx . . $ sighandle(d4f767463ce0a6b3).); |
| 772 |
signalcxx . . $ signal(c2d516773f91faf8).(SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!, sighandlecxx . . $ sighandle(d4f767463ce0a6b3).); |
| 773 |
|
| 774 |
conncxx . . $ conn. = register_dbuscxx . . $ register_dbus(24dc0d38ee6e2321).(); |
| 775 |
|
| 776 |
threshold = testintcxx . . $ testint(56759362374d8228).(argscxx . . $ args..thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold., optscxx . . $ opts..thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold., "No Link Quality Threshold Specified"); |
| 777 |
|
| 778 |
btdev_tcxx . . $ btdev_t#* btdev = testdevcxx . . $ testdev(2d65428583a747ef).(argscxx . . $ args..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optscxx . . $ opts..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., "No Devices Specified"); |
| 779 |
for (; NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != btdev; btdev = btdev->nextcxx . . $ devstruct#next.) { |
| 780 |
str2bacxx . . $ str2ba(17dfaccc23941df8).(btdev->btidcxx . . $ devstruct#btid., &(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 781 |
|
| 782 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Connecting to address %x:%x:%x:%x:%x:%x\n", btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[5], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[4], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[3], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[2], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[1], btdev->bdaddrcxx . . $ devstruct#bdaddr..bcxx . . $ $anonymous_type_f6ad386fb760be40_14#b.[0]); |
| 783 |
dev_id = hci_get_routecxx . . $ hci_get_route(1d45300bc66030a4).(&(btdev->bdaddrcxx . . $ devstruct#bdaddr.)); |
| 784 |
|
| 785 |
if (dev_id < 0) { |
| 786 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Device is not available.\n"); |
| 787 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 788 |
} |
| 789 |
|
| 790 |
btdev->ddcxx . . $ devstruct#dd. = hci_open_devcxx . . $ hci_open_dev(7864480464b09eea).(dev_id); |
| 791 |
if (btdev->ddcxx . . $ devstruct#dd. < 0) { |
| 792 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "HCI device open failed\n"); |
| 793 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 794 |
} |
| 795 |
|
| 796 |
foo = btconnectcxx . . $ btconnect(5898bd06b6080674).(btdev); |
| 797 |
if (!btdev->connectedcxx . . $ devstruct#connected.) |
| 798 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Using existing connection\n"); |
| 799 |
if (!foo) lq = -1; |
| 800 |
|
| 801 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Monitoring link quality\n"); |
| 802 |
btdev->trackcxx . . $ devstruct#track. = get_link_qualcxx . . $ get_link_qual(fd4f959995dcc4eb).(btdev); |
| 803 |
if (btdev->trackcxx . . $ devstruct#track. >= threshold) |
| 804 |
sendsignalcxx . . $ sendsignal(9a78dea97370318a).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, btdev); |
| 805 |
} |
| 806 |
|
| 807 |
// drop privs |
| 808 |
if ((argscxx . . $ args..uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid. || optscxx . . $ opts..uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid.) && (argscxx . . $ args..gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid. || optscxx . . $ opts..gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid.)) |
| 809 |
setreuidcxx . . $ setreuid(21cb2064190e2a90).(argscxx . . $ args..uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid.?argscxx . . $ args..uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid.:optscxx . . $ opts..uidcxx . . $ $anonymous_type_806a849bd12b9736_0#uid., argscxx . . $ args..gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid.?argscxx . . $ args..gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid.:optscxx . . $ opts..gidcxx . . $ $anonymous_type_806a849bd12b9736_0#gid.); |
| 810 |
|
| 811 |
while (run) { |
| 812 |
threshold = testintcxx . . $ testint(56759362374d8228).(argscxx . . $ args..thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold., optscxx . . $ opts..thresholdcxx . . $ $anonymous_type_806a849bd12b9736_0#threshold., "No Link Quality Threshold Specified"); |
| 813 |
interval = testintcxx . . $ testint(56759362374d8228).(argscxx . . $ args..intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval., optscxx . . $ opts..intervalcxx . . $ $anonymous_type_806a849bd12b9736_0#interval., "No Interval Specified"); |
| 814 |
|
| 815 |
btdev_tcxx . . $ btdev_t#* btdev = testdevcxx . . $ testdev(2d65428583a747ef).(argscxx . . $ args..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optscxx . . $ opts..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., "No Devices Specified"); |
| 816 |
for (; NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != btdev; btdev = btdev->nextcxx . . $ devstruct#next.) { |
| 817 |
// if device disconnects every 54s check before reconnect statement |
| 818 |
if (argscxx . . $ args..disconnecthackcxx . . $ $anonymous_type_806a849bd12b9736_0#disconnecthack. || optscxx . . $ opts..disconnecthackcxx . . $ $anonymous_type_806a849bd12b9736_0#disconnecthack.) |
| 819 |
lq = get_link_qualcxx . . $ get_link_qual(fd4f959995dcc4eb).(btdev); |
| 820 |
if (-1 == lq) |
| 821 |
btconnectcxx . . $ btconnect(5898bd06b6080674).(btdev); |
| 822 |
|
| 823 |
lq = get_link_qualcxx . . $ get_link_qual(fd4f959995dcc4eb).(btdev); |
| 824 |
|
| 825 |
if (lq >= threshold && btdev->trackcxx . . $ devstruct#track. < threshold) { |
| 826 |
// good quality, stop the screensaver |
| 827 |
sendsignalcxx . . $ sendsignal(9a78dea97370318a).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, btdev); |
| 828 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Device %s Connected\n", btdev->btidcxx . . $ devstruct#btid.); |
| 829 |
} |
| 830 |
else if (lq < threshold && btdev->trackcxx . . $ devstruct#track. >= threshold) { |
| 831 |
// bad quality, start the screensaver |
| 832 |
sendsignalcxx . . $ sendsignal(9a78dea97370318a).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, btdev); |
| 833 |
messagecxx . . $ message(7505dec36442ba15).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, "Device %s Disconnected\n", btdev->btidcxx . . $ devstruct#btid.); |
| 834 |
} |
| 835 |
btdev->trackcxx . . $ devstruct#track. = lq; |
| 836 |
} |
| 837 |
|
| 838 |
dbus_connection_read_writecxx . . $ dbus_connection_read_write(abcc320bcc2ff59b).(conncxx . . $ conn., interval); |
| 839 |
while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != (msg = dbus_connection_pop_messagecxx . . $ dbus_connection_pop_message(5f6abd88b5899afe).(conncxx . . $ conn.))) { |
| 840 |
if (dbus_message_is_method_callcxx . . $ dbus_message_is_method_call(f1395ecaabac588a).(msg, "cx.ath.matthew.bluemon.Bluemon", "Status")) |
| 841 |
handle_dbus_messagecxx . . $ handle_dbus_message(51fb7f56b8b56ff7).(msg, threshold); |
| 842 |
else if (dbus_message_is_method_callcxx . . $ dbus_message_is_method_call(f1395ecaabac588a).(msg, "org.freedesktop.DBus.Introspectable", "Introspect")) |
| 843 |
handle_introspection_messagecxx . . $ handle_introspection_message(ef6f40ad6aaa7be8).(msg); |
| 844 |
else if (dbus_message_is_method_callcxx . . $ dbus_message_is_method_call(f1395ecaabac588a).(msg, "org.freedesktop.DBus.Peer", "Ping")) { |
| 845 |
err = dbus_message_new_method_returncxx . . $ dbus_message_new_method_return(4b02851a30b507b9). (msg); |
| 846 |
dbus_connection_sendcxx . . $ dbus_connection_send(83479337446ba1bb).(conncxx . . $ conn., err, &serial); |
| 847 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(err); |
| 848 |
} |
| 849 |
else if (DBUS_MESSAGE_TYPE_METHOD_CALLcxx . . $ `<external>/9999628393408380398/dbus-protocol.h:236:9`! == dbus_message_get_typecxx . . $ dbus_message_get_type(a39774ac8f271178).(msg)) { |
| 850 |
err = dbus_message_new_errorcxx . . $ dbus_message_new_error(7af04b5fefa1fec6). (msg, "cx.ath.matthew.bluemon.error", "Unknown Method"); |
| 851 |
dbus_connection_sendcxx . . $ dbus_connection_send(83479337446ba1bb).(conncxx . . $ conn., err, &serial); |
| 852 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(err); |
| 853 |
} |
| 854 |
dbus_message_unrefcxx . . $ dbus_message_unref(ef6f40ad6aaa7be8).(msg); |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
btdev = testdevcxx . . $ testdev(2d65428583a747ef).(argscxx . . $ args..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., optscxx . . $ opts..btdevrootcxx . . $ $anonymous_type_806a849bd12b9736_0#btdevroot., "No Devices Specified"); |
| 859 |
while (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != btdev) { |
| 860 |
if (btdev->connectedcxx . . $ devstruct#connected.) { |
| 861 |
// disconnect bluetooth |
| 862 |
btdisconnectcxx . . $ btdisconnect(4614daf50ac1d508).(btdev); |
| 863 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != conncxx . . $ conn.) |
| 864 |
sendsignalcxx . . $ sendsignal(9a78dea97370318a).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, btdev); |
| 865 |
messagecxx . . $ message(7505dec36442ba15).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, "Disconnected %s\n", btdev->btidcxx . . $ devstruct#btid.); |
| 866 |
} |
| 867 |
hci_close_devcxx . . $ hci_close_dev(7864480464b09eea).(btdev->ddcxx . . $ devstruct#dd.); |
| 868 |
btdev_tcxx . . $ btdev_t#* temp = btdev->nextcxx . . $ devstruct#next.; |
| 869 |
freecxx . . $ free(5d22bdacc48458e8).(btdev); |
| 870 |
btdev = temp; |
| 871 |
} |
| 872 |
// disconnect socket |
| 873 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! != conncxx . . $ conn.) |
| 874 |
dbus_connection_unrefcxx . . $ dbus_connection_unref(5ffe6e60e141c747).(conncxx . . $ conn.); |
| 875 |
} |
| 876 |
|