@@ -45,6 +45,18 @@ static uint8_t ppp_frame_wrapped[] = {0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, 0x7D,
4545
4646static 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+
4860static 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
94106static 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 */
99114static 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+
384465ZTEST (modem_ppp , test_ip_frame_receive )
385466{
386467 struct net_pkt * pkt ;
0 commit comments