Skip to content

Commit 5e2af66

Browse files
committed
accm patch
1 parent 77f865b commit 5e2af66

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

include/zephyr/net/ppp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ struct lcp_options {
378378
};
379379

380380
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
381+
#define LCP_NUM_MY_OPTIONS 2
382+
#else
381383
#define LCP_NUM_MY_OPTIONS 1
382384
#endif
383385

@@ -422,9 +424,8 @@ struct ppp_context {
422424

423425
/** Magic-Number value */
424426
uint32_t magic;
425-
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
427+
426428
struct ppp_my_option_data my_options_data[LCP_NUM_MY_OPTIONS];
427-
#endif
428429
} lcp;
429430

430431
#if defined(CONFIG_NET_IPV4)

subsys/net/l2/ppp/lcp.c

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static void lcp_finished(struct ppp_fsm *fsm)
210210
ppp_link_terminated(ctx);
211211
}
212212

213+
213214
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
214215

215216
#define MRU_OPTION_LEN 4
@@ -268,15 +269,82 @@ static int lcp_nak_mru(struct ppp_context *ctx, struct net_pkt *pkt,
268269

269270
return 0;
270271
}
272+
#endif
273+
274+
#define ASYNC_MAP_OPTION_LEN 6
275+
276+
static int lcp_add_async_map(struct ppp_context *ctx, struct net_pkt *pkt)
277+
{
278+
NET_DBG("Async map length is: %d", ASYNC_MAP_OPTION_LEN);
279+
NET_DBG("Async map is: %u", ctx->lcp.my_options.async_map);
280+
281+
net_pkt_write_u8(pkt, ASYNC_MAP_OPTION_LEN);
282+
return net_pkt_write_be32(pkt, ctx->lcp.my_options.async_map);
283+
}
284+
285+
static int lcp_ack_async_map(struct ppp_context *ctx, struct net_pkt *pkt,
286+
uint8_t oplen)
287+
{
288+
int ret;
289+
uint32_t async_map;
290+
291+
/* Handle ACK : */
292+
if (oplen != sizeof(async_map)) {
293+
return -EINVAL;
294+
}
295+
296+
ret = net_pkt_read(pkt, &async_map, sizeof(async_map));
297+
if (ret) {
298+
return ret;
299+
}
300+
if (async_map != ctx->lcp.my_options.async_map) {
301+
/* Didn't acked our ASYNC_MAP: */
302+
return -EINVAL;
303+
}
304+
305+
return 0;
306+
}
307+
308+
static int lcp_nak_async_map(struct ppp_context *ctx, struct net_pkt *pkt,
309+
uint8_t oplen)
310+
{
311+
int ret;
312+
uint16_t async_map;
313+
314+
/* Handle NAK: accept only equal to ours */
315+
if (oplen != sizeof(async_map)) {
316+
return -EINVAL;
317+
}
318+
319+
ret = net_pkt_read(pkt, &async_map, sizeof(async_map));
320+
if (ret) {
321+
return ret;
322+
}
323+
324+
if (async_map != ctx->lcp.my_options.async_map) {
325+
return -EINVAL;
326+
}
327+
328+
return 0;
329+
}
271330

272331
static const struct ppp_my_option_info lcp_my_options[] = {
332+
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
273333
PPP_MY_OPTION(LCP_OPTION_MRU, lcp_add_mru, lcp_ack_mru, lcp_nak_mru),
334+
#endif
335+
PPP_MY_OPTION(LCP_OPTION_ASYNC_CTRL_CHAR_MAP, lcp_add_async_map, lcp_ack_async_map,
336+
lcp_nak_async_map),
274337
};
338+
275339
BUILD_ASSERT(ARRAY_SIZE(lcp_my_options) == LCP_NUM_MY_OPTIONS);
276340

277341
static struct net_pkt *lcp_config_info_add(struct ppp_fsm *fsm)
278342
{
279-
return ppp_my_options_add(fsm, MRU_OPTION_LEN);
343+
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
344+
return ppp_my_options_add(fsm, MRU_OPTION_LEN + ASYNC_MAP_OPTION_LEN);
345+
#else
346+
return ppp_my_options_add(fsm, ASYNC_MAP_OPTION_LEN);
347+
#endif
280348
}
281349

282350
static int lcp_config_info_nack(struct ppp_fsm *fsm, struct net_pkt *pkt,
@@ -297,7 +365,6 @@ static int lcp_config_info_nack(struct ppp_fsm *fsm, struct net_pkt *pkt,
297365

298366
return 0;
299367
}
300-
#endif
301368

302369
static void lcp_init(struct ppp_context *ctx)
303370
{
@@ -311,8 +378,8 @@ static void lcp_init(struct ppp_context *ctx)
311378
ppp_fsm_name_set(&ctx->lcp.fsm, ppp_proto2str(PPP_LCP));
312379

313380
ctx->lcp.my_options.mru = net_if_get_mtu(ctx->iface);
381+
ctx->lcp.my_options.async_map = 0xffffffff;
314382

315-
#if defined(CONFIG_NET_L2_PPP_OPTION_MRU)
316383
ctx->lcp.fsm.my_options.info = lcp_my_options;
317384
ctx->lcp.fsm.my_options.data = ctx->lcp.my_options_data;
318385
ctx->lcp.fsm.my_options.count = ARRAY_SIZE(lcp_my_options);
@@ -321,7 +388,6 @@ static void lcp_init(struct ppp_context *ctx)
321388
ctx->lcp.fsm.cb.config_info_req = lcp_config_info_req;
322389
ctx->lcp.fsm.cb.config_info_nack = lcp_config_info_nack;
323390
ctx->lcp.fsm.cb.config_info_rej = ppp_my_options_parse_conf_rej;
324-
#endif
325391

326392
ctx->lcp.fsm.cb.up = lcp_up;
327393
ctx->lcp.fsm.cb.down = lcp_down;

0 commit comments

Comments
 (0)