From ab71b2dba8f584ceebe8013773bee86e61c10be6 Mon Sep 17 00:00:00 2001 From: Kimmo Vaisanen Date: Fri, 13 Sep 2019 15:01:11 +0300 Subject: [PATCH] Cellular: Fix get_interface_name to not include leading zero Multihoming documentation about interface name: "Two character name string is concatenated with 8 bit value containing index which is incremented on each netif addition" Cellular uses context id as index and to follow LWIP (LWIP::Interface::get_interface_name), index does not include leading zeros. --- .../at_cellularcontexttest.cpp | 29 ++++++++++++++++++- .../framework/AT/AT_CellularContext.cpp | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp index 451c3a571c..00ee09e1e0 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp @@ -178,6 +178,18 @@ public: int _op; }; +class AT_CTX_cid: public AT_CellularContext { +public: + AT_CTX_cid(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) : + AT_CellularContext(at, device, apn) {} + virtual ~AT_CTX_cid() {} + + void set_cid(int cid) + { + _cid = cid; + } +}; + static int network_cb_count; static void network_cb(nsapi_event_t ev, intptr_t intptr) { @@ -250,6 +262,22 @@ TEST_F(TestAT_CellularContext, get_ip_address) EXPECT_TRUE(ip != NULL); } +TEST_F(TestAT_CellularContext, get_interface_name) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + AT_CellularDevice dev(&fh1); + AT_CTX_cid ctx(at, &dev); + + char ifn[5]; + EXPECT_TRUE(NULL == ctx.get_interface_name(ifn)); + + ctx.set_cid(1); + EXPECT_STREQ("ce1", ctx.get_interface_name(ifn)); + EXPECT_STREQ("ce1", ifn); +} + TEST_F(TestAT_CellularContext, attach) { EventQueue que; @@ -746,5 +774,4 @@ TEST_F(TestAT_CellularContext, get_timeout_for_operation) ctx1._op = -1; EXPECT_EQ(1800 * 1000, ctx1.do_op()); - } diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index d18918ec8f..2d782a5c85 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -244,7 +244,7 @@ char *AT_CellularContext::get_interface_name(char *interface_name) return NULL; } MBED_ASSERT(interface_name); - sprintf(interface_name, "ce%02d", _cid); + sprintf(interface_name, "ce%d", _cid); return interface_name; }