Add ringtones/wallpapers plugins, AT console, dialer USSD/*#06#, and SIM icon fix
This commit is contained in:
1 parent
e549aaf413
commit
dc59704547
64 files changed
+2743
-130
No files matched your search
@@ -21,8 +21,10 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <poll.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
@@ -88,7 +90,8 @@ constexpr const char* kIconSliders = "\xef\x87\x9e"; // U+F1DE sliders / con
|
||||
constexpr const char* kIconToggleOn = "\xef\x88\x85"; // U+F205 toggle on
|
||||
constexpr const char* kIconToggleOff = "\xef\x88\x84"; // U+F204 toggle off
|
||||
constexpr const char* kIconKey = "\xef\x82\x84"; // U+F084 key / PIN
|
||||
constexpr const char* kIconSim = "\xef\x9f\x84"; // U+F7C4 sim card / chip
|
||||
constexpr const char* kIconSim = "\xf3\xb0\x99\x95"; // U+F0655 nf-md-sim
|
||||
constexpr const char* kIconBell = "\xef\x83\xb3"; // U+F0F3 bell / ringtone
|
||||
|
||||
inline int64_t nowMs() {
|
||||
struct timespec ts {};
|
||||
@@ -344,6 +347,19 @@ inline void runAsyncCmd(const std::string& cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string shellQuote(const std::string& s) {
|
||||
std::string out = "'";
|
||||
for (char c : s) {
|
||||
if (c == '\'') {
|
||||
out += "'\\''";
|
||||
} else {
|
||||
out.push_back(c);
|
||||
}
|
||||
}
|
||||
out.push_back('\'');
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::string runCaptureCmd(const std::string& cmd, int* exitCodeOut = nullptr) {
|
||||
FILE* fp = ::popen(cmd.c_str(), "r");
|
||||
if (!fp) {
|
||||
@@ -1046,6 +1062,8 @@ inline void closeOtherPlugins(const char* selfPluginName) {
|
||||
{"xthemes.pid", "themes"},
|
||||
{"xmodem.pid", "modem"},
|
||||
{"xnetworks.pid", "networks"},
|
||||
{"xringtones.pid", "ringtones"},
|
||||
{"xwallpapers.pid", "wallpapers"},
|
||||
};
|
||||
for (const auto& p : kAllPlugins) {
|
||||
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
|
||||
@@ -1074,6 +1092,8 @@ inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
|
||||
"themes",
|
||||
"modem",
|
||||
"networks",
|
||||
"ringtones",
|
||||
"wallpapers",
|
||||
};
|
||||
for (const char* name : kPlugins) {
|
||||
if (selfPluginName && std::strcmp(name, selfPluginName) == 0) {
|
||||
@@ -1355,6 +1375,260 @@ inline std::vector<SmsThread> loadSmsThreads(const ContactBook& book) {
|
||||
return threads;
|
||||
}
|
||||
|
||||
struct DeviceImeis {
|
||||
std::string imei1;
|
||||
std::string imei2;
|
||||
std::string imeiSv;
|
||||
};
|
||||
|
||||
inline bool queryQrtrDmsImeis(DeviceImeis& out) {
|
||||
constexpr int kAfQipcrtr = 42;
|
||||
constexpr uint32_t kQrtrPortCtrl = 0xfffffffeu;
|
||||
constexpr uint32_t kQrtrTypeNewServer = 4;
|
||||
constexpr uint32_t kQrtrTypeNewLookup = 10;
|
||||
constexpr uint32_t kQmiServiceDms = 2;
|
||||
|
||||
struct SockAddrQrtr {
|
||||
unsigned short sq_family;
|
||||
uint32_t sq_node;
|
||||
uint32_t sq_port;
|
||||
};
|
||||
|
||||
struct QrtrCtrlPkt {
|
||||
uint32_t cmd;
|
||||
uint32_t service;
|
||||
uint32_t instance;
|
||||
uint32_t node;
|
||||
uint32_t port;
|
||||
} __attribute__((packed));
|
||||
|
||||
int fd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) return false;
|
||||
|
||||
SockAddrQrtr localSq {};
|
||||
socklen_t sl = sizeof(localSq);
|
||||
if (::getsockname(fd, reinterpret_cast<struct sockaddr*>(&localSq), &sl) < 0) {
|
||||
::close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
SockAddrQrtr ctrlSq {};
|
||||
ctrlSq.sq_family = kAfQipcrtr;
|
||||
ctrlSq.sq_node = localSq.sq_node;
|
||||
ctrlSq.sq_port = kQrtrPortCtrl;
|
||||
|
||||
QrtrCtrlPkt lookup {};
|
||||
lookup.cmd = kQrtrTypeNewLookup;
|
||||
lookup.service = kQmiServiceDms;
|
||||
lookup.instance = 0;
|
||||
|
||||
if (::sendto(fd, &lookup, sizeof(lookup), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&ctrlSq),
|
||||
sizeof(ctrlSq)) < 0) {
|
||||
::close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t dmsNode = 0;
|
||||
uint32_t dmsPort = 0;
|
||||
bool foundDms = false;
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
struct pollfd pfd { fd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 60) <= 0) break;
|
||||
QrtrCtrlPkt pkt {};
|
||||
ssize_t n = ::recv(fd, &pkt, sizeof(pkt), 0);
|
||||
if (n >= static_cast<ssize_t>(sizeof(pkt)) &&
|
||||
pkt.cmd == kQrtrTypeNewServer) {
|
||||
if (pkt.service == kQmiServiceDms && pkt.port != 0) {
|
||||
dmsNode = pkt.node;
|
||||
dmsPort = pkt.port;
|
||||
foundDms = true;
|
||||
break;
|
||||
}
|
||||
if (pkt.service == 0 && pkt.node == 0 && pkt.port == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
::close(fd);
|
||||
if (!foundDms) return false;
|
||||
|
||||
auto querySubImei = [&](uint32_t subType, std::string& imeiOut,
|
||||
std::string& svOut) {
|
||||
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (sfd < 0) return;
|
||||
|
||||
SockAddrQrtr dmsSq {};
|
||||
dmsSq.sq_family = kAfQipcrtr;
|
||||
dmsSq.sq_node = dmsNode;
|
||||
dmsSq.sq_port = dmsPort;
|
||||
|
||||
// 1. QMI_DMS_BIND_SUBSCRIPTION (0x0057), TLV 0x01 = uint32_t(subType)
|
||||
if (subType > 0) {
|
||||
uint8_t bindReq[14] = {
|
||||
0x00, 0x01, 0x00, // flags=0 (req), txn_id=1
|
||||
0x57, 0x00, // msg_id = 0x0057
|
||||
0x07, 0x00, // tlv_len = 7
|
||||
0x01, 0x04, 0x00, // TLV 0x01, len 4
|
||||
static_cast<uint8_t>(subType & 0xFF), 0x00, 0x00, 0x00
|
||||
};
|
||||
::sendto(sfd, bindReq, sizeof(bindReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&dmsSq),
|
||||
sizeof(dmsSq));
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 60) > 0) {
|
||||
uint8_t discard[256];
|
||||
::recv(sfd, discard, sizeof(discard), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. QMI_DMS_GET_DEVICE_SERIAL_NUMBERS (0x0025)
|
||||
uint8_t getIdsReq[7] = {
|
||||
0x00, 0x02, 0x00, // flags=0 (req), txn_id=2
|
||||
0x25, 0x00, // msg_id = 0x0025
|
||||
0x00, 0x00 // tlv_len = 0
|
||||
};
|
||||
if (::sendto(sfd, getIdsReq, sizeof(getIdsReq), 0,
|
||||
reinterpret_cast<const struct sockaddr*>(&dmsSq),
|
||||
sizeof(dmsSq)) >= 0) {
|
||||
struct pollfd pfd { sfd, POLLIN, 0 };
|
||||
if (::poll(&pfd, 1, 80) > 0) {
|
||||
uint8_t buf[512];
|
||||
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
|
||||
if (rlen >= 7 && buf[0] == 0x02 &&
|
||||
buf[3] == 0x25 && buf[4] == 0x00) {
|
||||
size_t tlvLen = static_cast<size_t>(buf[5]) |
|
||||
(static_cast<size_t>(buf[6]) << 8);
|
||||
size_t pos = 7;
|
||||
size_t end = std::min(static_cast<size_t>(rlen), 7 + tlvLen);
|
||||
while (pos + 3 <= end) {
|
||||
uint8_t tType = buf[pos];
|
||||
size_t tLen = static_cast<size_t>(buf[pos + 1]) |
|
||||
(static_cast<size_t>(buf[pos + 2]) << 8);
|
||||
pos += 3;
|
||||
if (pos + tLen > end) break;
|
||||
if (tType == 0x11 && tLen > 0) {
|
||||
imeiOut.assign(reinterpret_cast<const char*>(buf + pos), tLen);
|
||||
imeiOut = trimStr(imeiOut);
|
||||
} else if (tType == 0x13 && tLen > 0 && svOut.empty()) {
|
||||
svOut.assign(reinterpret_cast<const char*>(buf + pos), tLen);
|
||||
svOut = trimStr(svOut);
|
||||
}
|
||||
pos += tLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
::close(sfd);
|
||||
};
|
||||
|
||||
querySubImei(1, out.imei1, out.imeiSv);
|
||||
if (out.imei1.empty()) {
|
||||
querySubImei(0, out.imei1, out.imeiSv);
|
||||
}
|
||||
querySubImei(2, out.imei2, out.imeiSv);
|
||||
return !out.imei1.empty() || !out.imei2.empty();
|
||||
}
|
||||
|
||||
inline DeviceImeis queryDeviceImeis() {
|
||||
static DeviceImeis cached;
|
||||
if (!cached.imei1.empty() && !cached.imei2.empty()) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
DeviceImeis res = cached;
|
||||
queryQrtrDmsImeis(res);
|
||||
|
||||
if (res.imei1.empty() || res.imei2.empty()) {
|
||||
std::string helperOut = runCaptureCmd(
|
||||
"doas -n /usr/libexec/msm-modem-uim-selection imei 2>/dev/null");
|
||||
std::istringstream ss(helperOut);
|
||||
std::string line;
|
||||
while (std::getline(ss, line)) {
|
||||
if (line.rfind("IMEI1=", 0) == 0 && res.imei1.empty()) {
|
||||
res.imei1 = trimStr(line.substr(6));
|
||||
} else if (line.rfind("IMEI2=", 0) == 0 && res.imei2.empty()) {
|
||||
res.imei2 = trimStr(line.substr(6));
|
||||
} else if (line.rfind("IMEI_SV=", 0) == 0 && res.imeiSv.empty()) {
|
||||
res.imeiSv = trimStr(line.substr(8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (res.imei2.empty() && !res.imei1.empty()) {
|
||||
res.imei2 = res.imei1;
|
||||
}
|
||||
if (!res.imei1.empty()) {
|
||||
cached = res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline bool isUssdCode(const std::string& code) {
|
||||
std::string s = trimStr(code);
|
||||
return s.size() >= 3 && (s.front() == '*' || s.front() == '#') &&
|
||||
s.back() == '#';
|
||||
}
|
||||
|
||||
inline std::string sendModemUssd(const std::string& input,
|
||||
bool isReply = false,
|
||||
bool* outSessionActive = nullptr) {
|
||||
if (outSessionActive) *outSessionActive = false;
|
||||
std::string clean = trimStr(input);
|
||||
if (clean.empty()) return "Empty USSD request.";
|
||||
|
||||
int rc = 0;
|
||||
std::string cmd;
|
||||
if (isReply && !isUssdCode(clean)) {
|
||||
cmd = "mmcli -m any --3gpp-ussd-respond=" + shellQuote(clean) + " 2>&1";
|
||||
} else {
|
||||
cmd = "mmcli -m any --3gpp-ussd-cancel >/dev/null 2>&1; "
|
||||
"mmcli -m any --3gpp-ussd-initiate=" + shellQuote(clean) + " 2>&1";
|
||||
}
|
||||
|
||||
std::string out = trimStr(runCaptureCmd(cmd, &rc));
|
||||
size_t q1 = out.find('\'');
|
||||
size_t q2 = out.rfind('\'');
|
||||
if (q1 != std::string::npos && q2 != std::string::npos && q2 > q1) {
|
||||
out = out.substr(q1 + 1, q2 - q1 - 1);
|
||||
}
|
||||
if (out.empty()) {
|
||||
out = (rc == 0) ? "USSD request completed." : "USSD request failed.";
|
||||
}
|
||||
|
||||
if (outSessionActive) {
|
||||
std::string stOut = runCaptureCmd(
|
||||
"mmcli -m any -K 2>/dev/null | grep 'modem.3gpp.ussd.state'");
|
||||
if (stOut.find("user-response") != std::string::npos) {
|
||||
*outSessionActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Log USSD event to modemlog.tsv
|
||||
std::string logPath = getModemLogFilePath();
|
||||
ContactBook::ensureParentDir(logPath);
|
||||
std::ofstream logOut(logPath, std::ios::app);
|
||||
if (logOut.is_open()) {
|
||||
std::time_t now = std::time(nullptr);
|
||||
struct tm tmNow {};
|
||||
localtime_r(&now, &tmNow);
|
||||
char tbuf[32];
|
||||
std::strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &tmNow);
|
||||
std::string oneLine = out;
|
||||
for (char& c : oneLine) {
|
||||
if (c == '\n' || c == '\r' || c == '\t') c = ' ';
|
||||
}
|
||||
logOut << tbuf << "\tussd\t" << clean << "\t" << oneLine << "\n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline void cancelModemUssd() {
|
||||
runAsyncCmd("mmcli -m any --3gpp-ussd-cancel >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
} // namespace bananarchy
|
||||
|
||||
#endif // DWM_PLUGINS_PHONE_DATA_H
|
||||
Reference in new issue
Block a user