Skip to content

Commit 392ae8b

Browse files
committed
Try and connect to our Bluetooth service once we start, to try and start Android Auto
1 parent 28bc6a1 commit 392ae8b

File tree

2 files changed

+106
-42
lines changed

2 files changed

+106
-42
lines changed

mazda/wireless/wireless.cpp

+80-42
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "hu_uti.h"
2626

27+
#define HMI_BUS_ADDRESS "unix:path=/tmp/dbus_hmi_socket"
2728
#define SERVICE_BUS_ADDRESS "unix:path=/tmp/dbus_service_socket"
2829

2930
std::string IP_ADDRESS;
@@ -81,10 +82,80 @@ int handleWifiInfoRequestResponse(int fd, uint8_t *buffer, uint16_t length) {
8182
return msg.status();
8283
}
8384

85+
//uint32 15
86+
//uint32 3
87+
//uint32 1
88+
//uint32 100
89+
//struct {
90+
// array of bytes [
91+
// 2f 64 65 76 2f 70 74 73 2f 30 00 00 00 00 00 00 00 00 00 00 00
92+
// ]
93+
94+
95+
void handle_connect(char *pty){
96+
char buf[100];
97+
logd("\tPTY: %s\n", pty);
98+
int fd = open(pty, O_RDWR | O_NOCTTY | O_SYNC);
99+
HU::WifiInfoRequest request;
100+
request.set_ip_address(IP_ADDRESS.c_str());
101+
request.set_port(30515);
102+
103+
sendMessage(fd, request, 1);
104+
105+
logd("PTY opened\n");
106+
ssize_t len = 0;
107+
int loop = 1;
108+
while (loop) {
109+
ssize_t i = read(fd, buf, 4);
110+
len += i;
111+
if (len >= 4) {
112+
uint16_t size = be16toh(*(uint16_t *) buf);
113+
uint16_t type = be16toh(*(uint16_t * )(buf + 2));
114+
logd("Size: %u, MessageID: %u, left: %u\n", size, type);
115+
if (len >= size + 4) {
116+
uint8_t *buffer = (uint8_t *) malloc(size);
117+
i = 0;
118+
while (i < size) {
119+
i += read(fd, buffer, size);
120+
}
121+
switch (type) {
122+
case 1:
123+
handleWifiInfoRequest(fd, buffer, size);
124+
break;
125+
case 2:
126+
handleWifiSecurityRequest(fd, buffer, size);
127+
break;
128+
case 7:
129+
if (handleWifiInfoRequestResponse(fd, buffer, size) == 0) {
130+
loop = 0;
131+
}
132+
break;
133+
default:
134+
break;
135+
}
136+
}
137+
}
138+
}
139+
}
140+
141+
void BCAClient::ConnectionStatusResp(
142+
const uint32_t &serviceId,
143+
const uint32_t &connStatus,
144+
const uint32_t &btDeviceId,
145+
const uint32_t &status,
146+
const ::DBus::Struct <std::vector<uint8_t>> &terminalPath) {
147+
if (serviceId == 15 && connStatus == 3) {
148+
char *pty = (char *) malloc(terminalPath._1.size());
149+
std::copy(terminalPath._1.begin(), terminalPath._1.end(), pty);
150+
logd("\tPTY: %s\n", pty);
151+
handle_connect(pty);
152+
free(pty);
153+
}
154+
}
155+
84156
void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <std::vector<uint8_t>> &data) {
85157
char mac[18];
86158
char pty[100];
87-
char buf[100];
88159
logd("Signal Connected:\n");
89160
logd("\tType: %u\n", type);
90161
std::copy(data._1.begin() + 14, data._1.begin() + 32, mac);
@@ -94,47 +165,7 @@ void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <s
94165
if (data._1[36] == 15) {
95166
std::strncpy(pty, (char *) &data._1[48], 100);
96167
logd("\tPTY: %s\n", pty);
97-
int fd = open(pty, O_RDWR | O_NOCTTY | O_SYNC);
98-
HU::WifiInfoRequest request;
99-
request.set_ip_address(IP_ADDRESS.c_str());
100-
request.set_port(30515);
101-
102-
sendMessage(fd, request, 1);
103-
104-
logd("PTY opened\n");
105-
ssize_t len = 0;
106-
int loop = 1;
107-
while (loop) {
108-
ssize_t i = read(fd, buf, 4);
109-
len += i;
110-
if (len >= 4) {
111-
uint16_t size = be16toh(*(uint16_t *) buf);
112-
uint16_t type = be16toh(*(uint16_t * )(buf + 2));
113-
logd("Size: %u, MessageID: %u, left: %u\n", size, type);
114-
if (len >= size + 4) {
115-
uint8_t *buffer = (uint8_t *) malloc(size);
116-
i = 0;
117-
while (i < size) {
118-
i += read(fd, buffer, size);
119-
}
120-
switch (type) {
121-
case 1:
122-
handleWifiInfoRequest(fd, buffer, size);
123-
break;
124-
case 2:
125-
handleWifiSecurityRequest(fd, buffer, size);
126-
break;
127-
case 7:
128-
if (handleWifiInfoRequestResponse(fd, buffer, size) == 0) {
129-
loop = 0;
130-
}
131-
break;
132-
default:
133-
break;
134-
}
135-
}
136-
}
137-
}
168+
handle_connect(pty);
138169
}
139170
}
140171

@@ -174,15 +205,20 @@ void wireless_stop(){
174205
void wireless_thread() {
175206
static BDSClient *bds_client = NULL;
176207
static NMSClient *nms_client = NULL;
208+
static BCAClient *bca_client = NULL;
177209
DBus::default_dispatcher = &wireless_dispatcher;
178210

179211
logd("DBus::Glib::BusDispatcher attached\n");
180212

181213
try {
214+
DBus::Connection hmi_bus(HMI_BUS_ADDRESS, false);
215+
hmi_bus.register_bus();
182216
DBus::Connection service_bus(SERVICE_BUS_ADDRESS, false);
183217
service_bus.register_bus();
184218
bds_client = new BDSClient(service_bus, "/com/jci/bds", "com.jci.bds");
185219
nms_client = new NMSClient(service_bus, "/com/jci/nms", "com.jci.nms");
220+
bca_client = new BCAClient(hmi_bus, "/com/jci/bca", "com.jci.bca");
221+
186222

187223
::DBus::Struct <std::vector<int32_t>> interface_list;
188224
int32_t rvalue;
@@ -198,6 +234,8 @@ void wireless_thread() {
198234
}
199235
}
200236

237+
bca_client->StartAdd(15);
238+
201239

202240
wireless_dispatcher.enter();
203241
logd("Exiting");

mazda/wireless/wireless.h

+26
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ class NMSClient : public com::jci::nms_proxy, public DBus::ObjectProxy {
140140
virtual void WifiSignalStrength(const int32_t &ifcId, const uint32_t &strength) override {}
141141
};
142142

143+
class BCAClient : public com::jci::bca_proxy, public DBus::ObjectProxy {
144+
public:
145+
BCAClient(DBus::Connection &connection, const char *path, const char *name) : DBus::ObjectProxy(connection, path, name) {}
146+
virtual void DontShowOnConnectionSettingStatusResp(const uint32_t& btDeviceId, const bool& setting) override {}
147+
virtual void ConnectionStatusResp(const uint32_t& serviceId, const uint32_t& connStatus, const uint32_t& btDeviceId, const uint32_t& status, const ::DBus::Struct< std::vector< uint8_t > >& terminalPath);
148+
virtual void HftReadyStatus(const uint32_t& hftReady, const uint32_t& reasonCode, const uint32_t& appId) override {}
149+
virtual void ReadyStatus(const uint32_t& isReady, const uint32_t& reasonCode) override {}
150+
virtual void AddStatusResp(const uint32_t& addServiceId, const uint32_t& status) override {}
151+
virtual void DeviceUnbarringStatusResp(const uint32_t& btDeviceId, const uint32_t& status) override {}
152+
virtual void DeviceBluetoothSettingResp(const bool& btSetting) override {}
153+
virtual void AvailablePairedListResp(const uint32_t& totalPairedDevices, const ::DBus::Struct< std::vector< uint8_t > >& pairedDeviceList) override {}
154+
virtual void SupportedProfilesResp(const ::DBus::Struct< std::vector< uint8_t > >& supportedProfiles) override {}
155+
virtual void FirstHfpSupportedInfo(const bool& isHfpSupportedDevicePresent) override {}
156+
virtual void CarPlayConnectionStatus(const uint32_t& connStatus, const uint32_t& carPlayDeviceId) override {}
157+
virtual void AAutoEnableBt() override {}
158+
virtual void AAutoNoEntryAvailable(const uint32_t& deleteDeviceId) override {}
159+
virtual void ReqStartAndroidAutoPairing() override {}
160+
virtual void ReqStopAndroidAutoPairing() override {}
161+
virtual void ReqDeleteDevice(const uint32_t& deleteDeviceId) override {}
162+
virtual void AAPairingSeqResult(const bool& result) override {}
163+
virtual void AndroidAutoPairingTimeout() override {}
164+
virtual void RequestStartAutoDownload(const uint32_t& btDeviceId) override {}
165+
virtual void DisableBluetoothRsp(const uint32_t& activeCallStatus) override {}
166+
virtual void ConnectingCarPlayError() override {}
167+
};
168+
143169
void sendMessage(int fd, google::protobuf::MessageLite &message, uint16_t type);
144170
void handleWifiInfoRequest(int fd, uint8_t *buffer, uint16_t length);
145171
void handleWifiSecurityRequest(int fd, uint8_t *buffer, uint16_t length);

0 commit comments

Comments
 (0)