Browse code

pdbt: add pdb server message check

Related to 3c07e2351a94e4ff2cf3c6b9b9df4d7462cd5760 commit, but on server side.

Stefan Mititelu authored on 28/02/2020 10:17:49 • Stefan Mititelu committed on 28/02/2020 11:40:47
Showing 1 changed files
... ...
@@ -11,9 +11,15 @@ void pdb_msg_dbg(struct pdb_msg msg) {
11 11
     LERR("id = %d\n", msg.hdr.id);
12 12
     LERR("len = %d\n", msg.hdr.length);
13 13
     LERR("payload = ");
14
-    for (i = 0; i < msg.hdr.length - sizeof(msg.hdr); i++) {
15
-        LERR("%02X ", msg.bdy.payload[i]);
14
+
15
+    if(msg.hdr.length > sizeof(msg.hdr)) {
16
+        for (i = 0; i < msg.hdr.length - sizeof(msg.hdr); i++) {
17
+            LERR("%02X ", msg.bdy.payload[i]);
18
+        }
19
+    } else {
20
+        LERR("Incorrect value in msg.hdr.length \n");
16 21
     }
22
+
17 23
     LERR("\n");
18 24
 
19 25
     return ;
Browse code

pdb: new protocol between pdb_server and kama pdb module

Modified the communication protocol between the pdb clent <-> server such
that the server will give more feedback on scenarios like "pdb_id not found" or
"request number contains letters". New msg types or reply codes can be easily
added. Curent version of the protocol is 1 (0x01).
Also backwards compatibility is maintained when the first received byte is
different than the known versions (now, just 0x01).
Updated the http link for the get_carrier_germany script. Created a new perl
script to get german carrier id.
Updated doku (utils/pdbt/docs/network_protocol.txt).

added the perls script

Stefan Mititelu authored on 04/06/2015 08:34:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+#include "common.h"
2
+#include "log.h"
3
+#include <string.h>
4
+
5
+void pdb_msg_dbg(struct pdb_msg msg) {
6
+    int i;
7
+
8
+    LERR("version = %d\n", msg.hdr.version);
9
+    LERR("type = %d\n", msg.hdr.type);
10
+    LERR("code = %d\n", msg.hdr.code);
11
+    LERR("id = %d\n", msg.hdr.id);
12
+    LERR("len = %d\n", msg.hdr.length);
13
+    LERR("payload = ");
14
+    for (i = 0; i < msg.hdr.length - sizeof(msg.hdr); i++) {
15
+        LERR("%02X ", msg.bdy.payload[i]);
16
+    }
17
+    LERR("\n");
18
+
19
+    return ;
20
+}
21
+
22
+int pdb_msg_format_send(struct pdb_msg *msg,
23
+                        uint8_t version, uint8_t type,
24
+                        uint8_t code, uint16_t id,
25
+                        char *payload, uint16_t payload_len)
26
+{
27
+    msg->hdr.version    = version;
28
+    msg->hdr.type       = type;
29
+    msg->hdr.code       = code;
30
+    msg->hdr.id         = id;
31
+
32
+    if (payload == NULL) {
33
+        /* just ignore the NULL buff (called when just want to set the len) */
34
+        msg->hdr.length     = sizeof(struct pdb_hdr);
35
+        return 0;
36
+    } else {
37
+        msg->hdr.length     = sizeof(struct pdb_hdr) + payload_len;
38
+        memcpy(msg->bdy.payload, payload, payload_len);
39
+        return 0;
40
+    }
41
+
42
+    return 0;
43
+}