Skip to content

Commit 7a7d33b

Browse files
committed
detect wireless settings
1 parent 301d533 commit 7a7d33b

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

mazda/installer/config/androidauto/data_persist/dev/bin/headunit-wrapper

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ start_AAwireless()
6161
echo "====================" >> ${LOGPATH}
6262
}
6363

64+
iptables -A INPUT -p tcp --dport 30515 -m state --state NEW,ESTABLISHED -j ACCEPT
65+
6466
rm -f /tmp/root/headunit.status /tmp/root/headunit-wireless.status
6567

6668
# prevent conflict by Official AA

mazda/wireless/wireless.cpp

+55-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <thread>
1717
#include <unistd.h>
1818
#include <fcntl.h>
19-
19+
#include <fstream>
2020

2121
#include "hu.pb.h"
2222

@@ -26,6 +26,9 @@
2626

2727
#define SERVICE_BUS_ADDRESS "unix:path=/tmp/dbus_service_socket"
2828

29+
std::string IP_ADDRESS;
30+
std::string MAC_ADDRESS;
31+
2932

3033
void sendMessage(int fd, google::protobuf::MessageLite &message, uint16_t type) {
3134
int byteSize = message.ByteSize();
@@ -52,8 +55,8 @@ void handleWifiInfoRequest(int fd, uint8_t *buffer, uint16_t length) {
5255
logd("WifiInfoRequest: %s\n", msg.DebugString().c_str());
5356

5457
HU::WifiInfoResponse response;
55-
response.set_ip_address("192.168.53.1");
56-
response.set_port(5000);
58+
response.set_ip_address(IP_ADDRESS.c_str());
59+
response.set_port(30515);
5760
response.set_status(HU::WifiInfoResponse_Status_STATUS_SUCCESS);
5861

5962
sendMessage(fd, response, 7);
@@ -62,9 +65,9 @@ void handleWifiInfoRequest(int fd, uint8_t *buffer, uint16_t length) {
6265
void handleWifiSecurityRequest(int fd, uint8_t *buffer, uint16_t length) {
6366
HU::WifiSecurityReponse response;
6467

65-
response.set_ssid("MazdaCMU");
66-
response.set_bssid("0c:d9:c1:8f:7f:bb");
67-
response.set_key("password");
68+
response.set_ssid(hostapd_config("ssid").c_str());
69+
response.set_bssid(MAC_ADDRESS.c_str());
70+
response.set_key(hostapd_config("wpa_passphrase").c_str());
6871
response.set_security_mode(HU::WifiSecurityReponse_SecurityMode_WPA2_PERSONAL);
6972
response.set_access_point_type(HU::WifiSecurityReponse_AccessPointType_DYNAMIC);
7073

@@ -93,7 +96,7 @@ void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <s
9396
logd("\tPTY: %s\n", pty);
9497
int fd = open(pty, O_RDWR | O_NOCTTY | O_SYNC);
9598
HU::WifiInfoRequest request;
96-
request.set_ip_address("192.168.53.1");
99+
request.set_ip_address(IP_ADDRESS.c_str());
97100
request.set_port(30515);
98101

99102
sendMessage(fd, request, 1);
@@ -122,7 +125,7 @@ void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <s
122125
handleWifiSecurityRequest(fd, buffer, size);
123126
break;
124127
case 7:
125-
if(handleWifiInfoRequestResponse(fd, buffer, size) == 0){
128+
if (handleWifiInfoRequestResponse(fd, buffer, size) == 0) {
126129
loop = 0;
127130
}
128131
break;
@@ -135,8 +138,35 @@ void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <s
135138
}
136139
}
137140

141+
std::string hostapd_config(std::string key) {
142+
std::ifstream hostapd_file;
143+
hostapd_file.open("/tmp/current-session-hostapd.conf");
144+
145+
if (hostapd_file) {
146+
std::string line;
147+
size_t pos;
148+
while (hostapd_file.good()) {
149+
getline(hostapd_file, line); // get line from file
150+
if (line[0] != '#') {
151+
pos = line.find(key); // search
152+
if (pos != std::string::npos) // string::npos is returned if string is not found
153+
{
154+
int equalPosition = line.find("=");
155+
std::string value = line.substr(equalPosition + 1).c_str();
156+
return value.c_str();
157+
}
158+
}
159+
}
160+
return "";
161+
}
162+
else {
163+
return "";
164+
}
165+
};
166+
138167
void wireless_thread() {
139168
static BDSClient *bds_client = NULL;
169+
static NMSClient *nms_client = NULL;
140170
DBus::BusDispatcher dispatcher;
141171
DBus::default_dispatcher = &dispatcher;
142172

@@ -146,6 +176,23 @@ void wireless_thread() {
146176
DBus::Connection service_bus(SERVICE_BUS_ADDRESS, false);
147177
service_bus.register_bus();
148178
bds_client = new BDSClient(service_bus, "/com/jci/bds", "com.jci.bds");
179+
nms_client = new NMSClient(service_bus, "/com/jci/nms", "com.jci.nms");
180+
181+
::DBus::Struct <std::vector<int32_t>> interface_list;
182+
int32_t rvalue;
183+
nms_client->GetInterfaceList(rvalue, interface_list);
184+
::DBus::Struct <int32_t, int32_t, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, int32_t, int32_t, int32_t, int32_t> interface_params;
185+
for (auto const &interface: interface_list._1) {
186+
nms_client->GetInterfaceParams(interface, rvalue, interface_params);
187+
logd("Interface: %s, MAC: %s, IP: %s\n", interface_params._4.c_str(), interface_params._6.c_str(),
188+
interface_params._5.c_str());
189+
if (interface_params._4.compare("wlan0") == 0) {
190+
IP_ADDRESS.assign(interface_params._5.c_str());
191+
MAC_ADDRESS.assign(interface_params._6.c_str());
192+
}
193+
}
194+
195+
149196
dispatcher.enter();
150197
}
151198
catch (DBus::Error &error) {

mazda/wireless/wireless.h

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#ifndef HEADUNIT_WIRELESS_H
66
#define HEADUNIT_WIRELESS_H
7+
#include <string>
78
#include "../dbus/generated_cmu.h"
89
#include "hu.pb.h"
910

@@ -116,10 +117,34 @@ class BDSClient : public com::jci::bds_proxy, public DBus::ObjectProxy
116117

117118
};
118119

120+
class NMSClient : public com::jci::nms_proxy, public DBus::ObjectProxy {
121+
public:
122+
NMSClient(DBus::Connection&connection, const char *path, const char *name): DBus::ObjectProxy(connection, path, name){}
123+
124+
virtual void InterfaceArrive(const int32_t &ifcId) override {}
125+
virtual void InterfaceDeparture(const int32_t &ifcId) override {}
126+
virtual void InterfaceChanged(const int32_t &ifcId, const int32_t &changeMask) override {}
127+
virtual void InterfaceConnecting(const int32_t &ifcId) override {}
128+
virtual void InterfaceDisconnecting(const int32_t &ifcId) override {}
129+
virtual void InterfaceConnected(const int32_t &ifcId) override {}
130+
virtual void InterfaceDisconnected(const int32_t &ifcId, const int32_t &reason) override {}
131+
virtual void WifiScanResultsReady(const int32_t &ifcId) override {}
132+
virtual void ConnectResult(const int32_t &ifcId, const int32_t &reqId, const int32_t &result) override {}
133+
virtual void InterfaceWiFiModeChanged(const int32_t &ifcId, const int32_t &mode) override {}
134+
virtual void WiFiAPClientConnected(const int32_t &ifcId, const std::string &bssid) override {}
135+
virtual void WiFiAPClientDisconnected(const int32_t &ifcId, const std::string &bssid) override {}
136+
virtual void APOpenInfo(const int32_t &ifcId, const ::DBus::Struct <std::string, uint32_t, int32_t, int32_t> &config) override {}
137+
virtual void APWepInfo(const int32_t &ifcId, const ::DBus::Struct<::DBus::Struct < std::string, uint32_t, int32_t, int32_t>, ::DBus::Struct <std::string, std::string, std::string, std::string>>& config) override {}
138+
virtual void APWpaInfo(const int32_t &ifcId, const ::DBus::Struct<::DBus::Struct < std::string, uint32_t, int32_t, int32_t>, ::DBus::Struct <int32_t, std::string>>& config) override {}
139+
virtual void InterfaceMonitorData(const int32_t &ifcId, const ::DBus::Struct <uint64_t, uint64_t> &statistics) override {}
140+
virtual void WifiSignalStrength(const int32_t &ifcId, const uint32_t &strength) override {}
141+
};
142+
119143
void sendMessage(int fd, google::protobuf::MessageLite &message, uint16_t type);
120144
void handleWifiInfoRequest(int fd, uint8_t *buffer, uint16_t length);
121145
void handleWifiSecurityRequest(int fd, uint8_t *buffer, uint16_t length);
122146
int handleWifiInfoRequestResponse(int fd, uint8_t *buffer, uint16_t length);
147+
std::string hostapd_config(std::string key);
123148
void wireless_thread();
124149

125150
#endif //HEADUNIT_WIRELESS_H

0 commit comments

Comments
 (0)