Cellular: Refactor is_protocol_supported() into CellularProperty

pull/12265/head
Ari Parkkila 2020-01-15 02:47:21 -08:00
parent e2cb18061e
commit ceea992b40
33 changed files with 64 additions and 70 deletions

View File

@ -81,10 +81,6 @@ public:
{
return 200;
}
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
{
return true;
}
virtual nsapi_error_t socket_close_impl(int sock_id)
{
return NSAPI_ERROR_OK;

View File

@ -44,11 +44,6 @@ public:
create_error = NSAPI_ERROR_OK;
}
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
{
return bool_value;
}
virtual nsapi_error_t socket_close_impl(int sock_id)
{
return NSAPI_ERROR_OK;
@ -201,10 +196,10 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK, *_dev);
st.bool_value = false;
AT_CellularDevice_stub::supported_bool = 0;
EXPECT_EQ(st.socket_open(NULL, NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
st.bool_value = true;
AT_CellularDevice_stub::supported_bool = 1;
AT_CellularDevice_stub::max_sock_value = 0;
nsapi_socket_t sock = &st.socket;
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);

View File

@ -59,6 +59,8 @@ public:
PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
PROPERTY_AT_COPS_FALLBACK_AUTO, // 0 = not supported, 1 = supported. Does modem support mode 4 of AT+COPS= ?
PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
PROPERTY_IP_TCP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
PROPERTY_IP_UDP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
PROPERTY_MAX
};

View File

@ -157,13 +157,28 @@ nsapi_error_t AT_CellularStack::socket_stack_init()
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
if (!is_protocol_supported(proto) || !handle) {
if (!handle) {
return NSAPI_ERROR_UNSUPPORTED;
}
if (proto == NSAPI_UDP) {
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_UDP)) {
return NSAPI_ERROR_UNSUPPORTED;
}
} else if (proto == NSAPI_TCP) {
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_TCP)) {
return NSAPI_ERROR_UNSUPPORTED;
}
} else {
return NSAPI_ERROR_UNSUPPORTED;
}
_socket_mutex.lock();
if (!_socket) {
if (_device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT) == 0) {
return NSAPI_ERROR_NO_SOCKET;
}
if (socket_stack_init() != NSAPI_ERROR_OK) {
_socket_mutex.unlock();
return NSAPI_ERROR_NO_SOCKET;

View File

@ -135,13 +135,6 @@ protected:
bool txfull_event; // socket event after wouldblock
};
/**
* Checks if modem supports the given protocol
*
* @param protocol Protocol type
*/
virtual bool is_protocol_supported(nsapi_protocol_t protocol) = 0;
/**
* Implements modem specific AT command set for socket closing
*

View File

@ -114,6 +114,8 @@ void GEMALTO_CINTERION::init_module_bgs2()
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
10, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
set_cellular_properties(cellular_properties);
_module = ModuleBGS2;
@ -140,6 +142,8 @@ void GEMALTO_CINTERION::init_module_els61()
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
10, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
set_cellular_properties(cellular_properties);
_module = ModuleELS61;
@ -166,6 +170,8 @@ void GEMALTO_CINTERION::init_module_ems31()
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
10, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
set_cellular_properties(cellular_properties);
_module = ModuleEMS31;
@ -192,6 +198,8 @@ void GEMALTO_CINTERION::init_module_ehs5e()
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
10, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
set_cellular_properties(cellular_properties);
_module = ModuleEHS5E;

View File

@ -132,11 +132,6 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
return err;
}
bool GEMALTO_CINTERION_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_close_impl(int sock_id)
{
tr_debug("Cinterion close %d", sock_id);

View File

@ -32,8 +32,6 @@ protected:
virtual nsapi_error_t socket_stack_init();
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t socket_close_impl(int sock_id);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);

View File

@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
GENERIC_AT3GPP::GENERIC_AT3GPP(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -46,6 +46,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
0, // PROPERTY_AT_CGEREP,
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
7, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -128,11 +128,6 @@ void QUECTEL_BC95_CellularStack::urc_nsocli()
}
bool QUECTEL_BC95_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t QUECTEL_BC95_CellularStack::socket_close_impl(int sock_id)
{
CellularSocket *sock = find_socket(sock_id);

View File

@ -38,8 +38,6 @@ protected: // NetworkStack
protected: // AT_CellularStack
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t socket_close_impl(int sock_id);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);

View File

@ -63,6 +63,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP,
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
12, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinName rst)

View File

@ -222,11 +222,6 @@ void QUECTEL_BG96_CellularStack::urc_qiurc(urc_type_t urc_type)
}
}
bool QUECTEL_BG96_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t QUECTEL_BG96_CellularStack::socket_close_impl(int sock_id)
{
_at.set_at_timeout(BG96_CLOSE_SOCKET_TIMEOUT);

View File

@ -59,8 +59,6 @@ protected: // NetworkStack
protected: // AT_CellularStack
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t socket_close_impl(int sock_id);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);

View File

@ -64,6 +64,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP,
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst)

View File

@ -42,6 +42,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
6, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -217,11 +217,6 @@ nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init()
return NSAPI_ERROR_OK;
}
bool QUECTEL_M26_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t QUECTEL_M26_CellularStack::socket_close_impl(int sock_id)
{
tr_debug("QUECTEL_M26_CellularStack:%s:%u:", __FUNCTION__, __LINE__);

View File

@ -46,8 +46,6 @@ protected: // AT_CellularStack
virtual nsapi_error_t socket_stack_init();
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t socket_close_impl(int sock_id);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);

View File

@ -44,6 +44,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP,
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -46,6 +46,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
0, // PROPERTY_AT_CGEREP
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
7, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
RM1000_AT::RM1000_AT(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -87,11 +87,6 @@ void RM1000_AT_CellularStack::RUSOCL_URC()
clear_socket(socket);
}
bool RM1000_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t RM1000_AT_CellularStack::create_socket_impl(CellularSocket *socket)
{
tr_debug("RM1000_AT_CellularStack::create_socket_impl");
@ -103,7 +98,7 @@ nsapi_error_t RM1000_AT_CellularStack::create_socket_impl(CellularSocket *socket
err = _at.at_cmd_int("+RSOCR", "=0", sock_id);
} else if (socket->proto == NSAPI_TCP) {
err = _at.at_cmd_int("+RSOCR", "=1", sock_id);
} // Unsupported protocol is checked in "is_protocol_supported" function
} // Unsupported protocol is checked in socket_open()
if ((err != NSAPI_ERROR_OK) || (sock_id == -1)) {
tr_error("RM1000_AT_CellularStack::create_socket_impl error sock_id=%d err=%d", sock_id, err);

View File

@ -61,8 +61,6 @@ protected: // AT_CellularStack
*/
static const int RM1000_MAX_PACKET_SIZE = 1024;
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);

View File

@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP,
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh)

View File

@ -60,6 +60,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
//the delay between sending AT commands

View File

@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
7, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_G3XX)
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
@ -63,6 +65,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
7, // PROPERTY_SOCKET_COUNT
1, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
#else
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
@ -83,6 +87,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
0, // PROPERTY_AT_CGEREP
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
#endif

View File

@ -107,11 +107,6 @@ void UBLOX_AT_CellularStack::UUPSDD_URC()
clear_socket(socket);
}
bool UBLOX_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
}
nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
{
int sock_id = SOCKET_UNUSED;
@ -121,7 +116,7 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
err = _at.at_cmd_int("+USOCR", "=17", sock_id);
} else if (socket->proto == NSAPI_TCP) {
err = _at.at_cmd_int("+USOCR", "=6", sock_id);
} // Unsupported protocol is checked in "is_protocol_supported" function
} // Unsupported protocol is checked in socket_open()
if ((err != NSAPI_ERROR_OK) || (sock_id == -1)) {
return NSAPI_ERROR_NO_SOCKET;

View File

@ -65,8 +65,6 @@ protected:
*/
static const int UBLOX_MAX_PACKET_SIZE = 1024;
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);

View File

@ -38,6 +38,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
0, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
7, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
1, // PROPERTY_IP_UDP
};
UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh)

View File

@ -64,11 +64,6 @@ void UBLOX_N2XX_CellularStack::NSONMI_URC()
}
}
bool UBLOX_N2XX_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
{
return (protocol == NSAPI_UDP);
}
nsapi_error_t UBLOX_N2XX_CellularStack::create_socket_impl(CellularSocket *socket)
{
int sock_id = -1;

View File

@ -52,8 +52,6 @@ protected:
*/
static const int N2XX_MAX_PACKET_SIZE = 512;
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,

View File

@ -40,6 +40,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_G3XX)
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
@ -64,6 +66,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
#else
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
@ -84,6 +88,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
0, // PROPERTY_AT_CGEREP
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
0, // PROPERTY_SOCKET_COUNT
0, // PROPERTY_IP_TCP
0, // PROPERTY_IP_UDP
};
#endif