mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-11 16:07:13 +00:00
Check if packet is decrypted before using portnum when converting to JSON (#2857)
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
parent
f301e236eb
commit
37c3d15978
@ -516,6 +516,7 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
JSONObject msgPayload;
|
JSONObject msgPayload;
|
||||||
JSONObject jsonObj;
|
JSONObject jsonObj;
|
||||||
|
|
||||||
|
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||||
switch (mp->decoded.portnum) {
|
switch (mp->decoded.portnum) {
|
||||||
case meshtastic_PortNum_TEXT_MESSAGE_APP: {
|
case meshtastic_PortNum_TEXT_MESSAGE_APP: {
|
||||||
msgType = "text";
|
msgType = "text";
|
||||||
@ -543,7 +544,6 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
msgType = "telemetry";
|
msgType = "telemetry";
|
||||||
meshtastic_Telemetry scratch;
|
meshtastic_Telemetry scratch;
|
||||||
meshtastic_Telemetry *decoded = NULL;
|
meshtastic_Telemetry *decoded = NULL;
|
||||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Telemetry_msg, &scratch)) {
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Telemetry_msg, &scratch)) {
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
@ -564,14 +564,12 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for telemetry message!\n");
|
LOG_ERROR("Error decoding protobuf for telemetry message!\n");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case meshtastic_PortNum_NODEINFO_APP: {
|
case meshtastic_PortNum_NODEINFO_APP: {
|
||||||
msgType = "nodeinfo";
|
msgType = "nodeinfo";
|
||||||
meshtastic_User scratch;
|
meshtastic_User scratch;
|
||||||
meshtastic_User *decoded = NULL;
|
meshtastic_User *decoded = NULL;
|
||||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_User_msg, &scratch)) {
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_User_msg, &scratch)) {
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
@ -583,14 +581,12 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for nodeinfo message!\n");
|
LOG_ERROR("Error decoding protobuf for nodeinfo message!\n");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case meshtastic_PortNum_POSITION_APP: {
|
case meshtastic_PortNum_POSITION_APP: {
|
||||||
msgType = "position";
|
msgType = "position";
|
||||||
meshtastic_Position scratch;
|
meshtastic_Position scratch;
|
||||||
meshtastic_Position *decoded = NULL;
|
meshtastic_Position *decoded = NULL;
|
||||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Position_msg, &scratch)) {
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Position_msg, &scratch)) {
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
@ -627,15 +623,12 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for position message!\n");
|
LOG_ERROR("Error decoding protobuf for position message!\n");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case meshtastic_PortNum_WAYPOINT_APP: {
|
case meshtastic_PortNum_WAYPOINT_APP: {
|
||||||
msgType = "position";
|
msgType = "position";
|
||||||
meshtastic_Waypoint scratch;
|
meshtastic_Waypoint scratch;
|
||||||
meshtastic_Waypoint *decoded = NULL;
|
meshtastic_Waypoint *decoded = NULL;
|
||||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Waypoint_msg, &scratch)) {
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Waypoint_msg, &scratch)) {
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
@ -650,14 +643,12 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for position message!\n");
|
LOG_ERROR("Error decoding protobuf for position message!\n");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case meshtastic_PortNum_NEIGHBORINFO_APP: {
|
case meshtastic_PortNum_NEIGHBORINFO_APP: {
|
||||||
msgType = "neighborinfo";
|
msgType = "neighborinfo";
|
||||||
meshtastic_NeighborInfo scratch;
|
meshtastic_NeighborInfo scratch;
|
||||||
meshtastic_NeighborInfo *decoded = NULL;
|
meshtastic_NeighborInfo *decoded = NULL;
|
||||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_NeighborInfo_msg,
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_NeighborInfo_msg,
|
||||||
&scratch)) {
|
&scratch)) {
|
||||||
@ -678,13 +669,15 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for neighborinfo message!\n");
|
LOG_ERROR("Error decoding protobuf for neighborinfo message!\n");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// add more packet types here if needed
|
// add more packet types here if needed
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOG_WARN("Couldn't convert encrypted payload of MeshPacket to JSON\n");
|
||||||
|
}
|
||||||
|
|
||||||
jsonObj["id"] = new JSONValue((uint)mp->id);
|
jsonObj["id"] = new JSONValue((uint)mp->id);
|
||||||
jsonObj["timestamp"] = new JSONValue((uint)mp->rx_time);
|
jsonObj["timestamp"] = new JSONValue((uint)mp->rx_time);
|
||||||
|
Loading…
Reference in New Issue
Block a user