Skip to content

Commit 51b424e

Browse files
JordanYateskartben
authored andcommitted
tests: modem: ppp: test custom ACCM's
Test the wrapping functions with custom asynchronous command character maps. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 4494b42 commit 51b424e

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

subsys/net/l2/ppp/ppp_l2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ uint32_t ppp_peer_async_control_character_map(struct net_if *iface)
350350
{
351351
struct ppp_context *ctx;
352352

353+
#ifndef CONFIG_ZTEST
353354
__ASSERT(net_if_l2(iface) == &NET_L2_GET_NAME(PPP), "Not PPP L2");
355+
#endif /* !CONFIG_ZTEST */
354356
ctx = net_if_l2_data(iface);
355357
return ctx->lcp.peer_options.async_map;
356358
}

tests/subsys/modem/modem_ppp/src/main.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ static uint8_t ppp_frame_wrapped[] = {0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, 0x7D,
4545

4646
static uint8_t ppp_frame_unwrapped[] = {0xC0, 0x21, 0x01, 0x01, 0x00, 0x04};
4747

48+
/* Custom ACCM (Only 0-15 need to be escaped) */
49+
static uint32_t accm_custom1 = 0x0000ffff;
50+
static uint8_t ppp_frame_wrapped_accm1[] = {0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, 0x16, 0x7D,
51+
0x21, 0x7D, 0x20, 0x7D, 0x24, 0x51, 0x21, 0x7E};
52+
53+
/* Custom ACCM (Only 16-31 need to be escaped) */
54+
static uint32_t accm_custom2 = 0xffff0000;
55+
static uint8_t ppp_frame_wrapped_accm2[] = {0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, 0x7D, 0x36,
56+
0x01, 0x00, 0x04, 0x51, 0x21, 0x7E};
57+
58+
static uint8_t ppp_frame_unwrapped_accm[] = {0xC0, 0x21, 0x16, 0x01, 0x00, 0x04};
59+
4860
static uint8_t ip_frame_wrapped[] = {
4961
0x7E, 0xFF, 0x7D, 0x23, 0x7D, 0x20, 0x21, 0x45, 0x7D, 0x20, 0x7D, 0x20, 0x29, 0x87, 0x6E,
5062
0x40, 0x7D, 0x20, 0xE8, 0x7D, 0x31, 0xC1, 0xE9, 0x7D, 0x23, 0xFB, 0x7D, 0x25, 0x20, 0x7D,
@@ -94,10 +106,14 @@ static enum net_verdict test_net_l2_recv(struct net_if *iface, struct net_pkt *p
94106
static struct net_l2 test_net_l2 = {
95107
.recv = test_net_l2_recv,
96108
};
109+
static struct ppp_context test_net_l2_data = {
110+
.lcp.peer_options.async_map = 0xffffffff,
111+
};
97112

98113
/* This emulates the network interface device which will receive unwrapped network packets */
99114
static struct net_if_dev test_net_if_dev = {
100115
.l2 = &test_net_l2,
116+
.l2_data = &test_net_l2_data,
101117
.link_addr.addr = {0x00, 0x00, 0x5E, 0x00, 0x53, 0x01},
102118
.link_addr.len = NET_ETH_ADDR_LEN,
103119
.link_addr.type = NET_LINK_DUMMY,
@@ -287,6 +303,9 @@ static void test_modem_ppp_before(void *f)
287303
net_pkt_unref(received_packets[i]);
288304
}
289305

306+
/* Reset ACCM */
307+
test_net_l2_data.lcp.peer_options.async_map = 0xffffffff;
308+
290309
/* Reset packets received buffer */
291310
received_packets_len = 0;
292311

@@ -381,6 +400,68 @@ ZTEST(modem_ppp, test_ppp_frame_send)
381400
"Wrapped frame content is incorrect");
382401
}
383402

403+
ZTEST(modem_ppp, test_ppp_frame_send_custom_accm1)
404+
{
405+
struct net_pkt *pkt;
406+
int ret;
407+
408+
/* Allocate net pkt */
409+
pkt = net_pkt_alloc_with_buffer(&test_iface, 256, AF_UNSPEC, 0, K_NO_WAIT);
410+
411+
zassert_true(pkt != NULL, "Failed to allocate network packet");
412+
413+
/* Set network packet data */
414+
net_pkt_cursor_init(pkt);
415+
ret = net_pkt_write(pkt, ppp_frame_unwrapped_accm, sizeof(ppp_frame_unwrapped_accm));
416+
zassert_true(ret == 0, "Failed to write data to allocated network packet");
417+
net_pkt_set_ppp(pkt, true);
418+
419+
test_net_l2_data.lcp.peer_options.async_map = accm_custom1;
420+
421+
/* Send network packet */
422+
zassert_true(test_net_send(pkt) == 0, "Failed to send PPP pkt");
423+
424+
/* Give modem ppp time to wrap and send frame */
425+
k_msleep(1000);
426+
427+
/* Get any sent data */
428+
ret = modem_backend_mock_get(&mock, buffer, sizeof(buffer));
429+
zassert_true(ret == sizeof(ppp_frame_wrapped_accm1), "Wrapped frame length incorrect");
430+
zassert_true(memcmp(buffer, ppp_frame_wrapped_accm1, ret) == 0,
431+
"Wrapped frame content is incorrect");
432+
}
433+
434+
ZTEST(modem_ppp, test_ppp_frame_send_custom_accm2)
435+
{
436+
struct net_pkt *pkt;
437+
int ret;
438+
439+
/* Allocate net pkt */
440+
pkt = net_pkt_alloc_with_buffer(&test_iface, 256, AF_UNSPEC, 0, K_NO_WAIT);
441+
442+
zassert_true(pkt != NULL, "Failed to allocate network packet");
443+
444+
/* Set network packet data */
445+
net_pkt_cursor_init(pkt);
446+
ret = net_pkt_write(pkt, ppp_frame_unwrapped_accm, sizeof(ppp_frame_unwrapped_accm));
447+
zassert_true(ret == 0, "Failed to write data to allocated network packet");
448+
net_pkt_set_ppp(pkt, true);
449+
450+
test_net_l2_data.lcp.peer_options.async_map = accm_custom2;
451+
452+
/* Send network packet */
453+
zassert_true(test_net_send(pkt) == 0, "Failed to send PPP pkt");
454+
455+
/* Give modem ppp time to wrap and send frame */
456+
k_msleep(1000);
457+
458+
/* Get any sent data */
459+
ret = modem_backend_mock_get(&mock, buffer, sizeof(buffer));
460+
zassert_true(ret == sizeof(ppp_frame_wrapped_accm2), "Wrapped frame length incorrect");
461+
zassert_true(memcmp(buffer, ppp_frame_wrapped_accm2, ret) == 0,
462+
"Wrapped frame content is incorrect");
463+
}
464+
384465
ZTEST(modem_ppp, test_ip_frame_receive)
385466
{
386467
struct net_pkt *pkt;

0 commit comments

Comments
 (0)