From ada44a62f40b5eb7e804ad0dcb659d3079f805cd Mon Sep 17 00:00:00 2001 From: Balaji Subramanyam Date: Mon, 12 Oct 2020 13:09:43 -0700 Subject: [PATCH] Add nsapi types for IP TOS and fix opt length check --- connectivity/lwipstack/source/LWIPStack.cpp | 2 +- .../netsocket/include/netsocket/nsapi_types.h | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/connectivity/lwipstack/source/LWIPStack.cpp b/connectivity/lwipstack/source/LWIPStack.cpp index dcb9d2581f..0501f7058f 100644 --- a/connectivity/lwipstack/source/LWIPStack.cpp +++ b/connectivity/lwipstack/source/LWIPStack.cpp @@ -665,7 +665,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co } case NSAPI_IPTOS: - if (optlen != sizeof(int)) { + if (optlen != sizeof(u8_t)) { return NSAPI_ERROR_UNSUPPORTED; } s->conn->pcb.ip->tos = (u8_t)(*(const int *)optval); diff --git a/connectivity/netsocket/include/netsocket/nsapi_types.h b/connectivity/netsocket/include/netsocket/nsapi_types.h index 6c6a7558ca..dbe071c357 100644 --- a/connectivity/netsocket/include/netsocket/nsapi_types.h +++ b/connectivity/netsocket/include/netsocket/nsapi_types.h @@ -27,6 +27,50 @@ extern "C" { #endif +/* + * The Type of Service provides an indication of the abstract + * parameters of the quality of service desired. These parameters are + * to be used to guide the selection of the actual service parameters + * when transmitting a datagram through a particular network. Several + * networks offer service precedence, which somehow treats high + * precedence traffic as more important than other traffic (generally + * by accepting only traffic above a certain precedence at time of high + * load). The major choice is a three way tradeoff between low-delay, + * high-reliability, and high-throughput. + * The use of the Delay, Throughput, and Reliability indications may + * increase the cost (in some sense) of the service. In many networks + * better performance for one of these parameters is coupled with worse + * performance on another. Except for very unusual cases at most two + * of these three indications should be set. + */ +#define NSAPI_IPTOS_TOS_MASK 0x1E +#define NSAPI_IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) +#define NSAPI_IPTOS_LOWDELAY 0x10 +#define NSAPI_IPTOS_THROUGHPUT 0x08 +#define NSAPI_IPTOS_RELIABILITY 0x04 +#define NSAPI_IPTOS_LOWCOST 0x02 +#define NSAPI_IPTOS_MINCOST IPTOS_LOWCOST + +/* + * The Network Control precedence designation is intended to be used + * within a network only. The actual use and control of that + * designation is up to each network. The Internetwork Control + * designation is intended for use by gateway control originators only. + * If the actual use of these precedence designations is of concern to + * a particular network, it is the responsibility of that network to + * control the access to, and use of, those precedence designations. + */ +#define NSAPI_IPTOS_PREC_MASK 0xe0 +#define NSAPI_IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) +#define NSAPI_IPTOS_PREC_NETCONTROL 0xe0 +#define NSAPI_IPTOS_PREC_INTERNETCONTROL 0xc0 +#define NSAPI_IPTOS_PREC_CRITIC_ECP 0xa0 +#define NSAPI_IPTOS_PREC_FLASHOVERRIDE 0x80 +#define NSAPI_IPTOS_PREC_FLASH 0x60 +#define NSAPI_IPTOS_PREC_IMMEDIATE 0x40 +#define NSAPI_IPTOS_PREC_PRIORITY 0x20 +#define NSAPI_IPTOS_PREC_ROUTINE 0x00 + /** Enum of standardized error codes * * Valid error codes have negative values and may