mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			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.pull/11488/head
							parent
							
								
									f5dd7db8c7
								
							
						
					
					
						commit
						ab71b2dba8
					
				| 
						 | 
					@ -178,6 +178,18 @@ public:
 | 
				
			||||||
    int _op;
 | 
					    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 int network_cb_count;
 | 
				
			||||||
static void network_cb(nsapi_event_t ev, intptr_t intptr)
 | 
					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);
 | 
					    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)
 | 
					TEST_F(TestAT_CellularContext, attach)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EventQueue que;
 | 
					    EventQueue que;
 | 
				
			||||||
| 
						 | 
					@ -746,5 +774,4 @@ TEST_F(TestAT_CellularContext, get_timeout_for_operation)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ctx1._op = -1;
 | 
					    ctx1._op = -1;
 | 
				
			||||||
    EXPECT_EQ(1800 * 1000, ctx1.do_op());
 | 
					    EXPECT_EQ(1800 * 1000, ctx1.do_op());
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -244,7 +244,7 @@ char *AT_CellularContext::get_interface_name(char *interface_name)
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    MBED_ASSERT(interface_name);
 | 
					    MBED_ASSERT(interface_name);
 | 
				
			||||||
    sprintf(interface_name, "ce%02d", _cid);
 | 
					    sprintf(interface_name, "ce%d", _cid);
 | 
				
			||||||
    return interface_name;
 | 
					    return interface_name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue