Skip to content

Commit ada44a6

Browse files
committed
Add nsapi types for IP TOS and fix opt length check
1 parent 7f2c00b commit ada44a6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

connectivity/lwipstack/source/LWIPStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
665665
}
666666

667667
case NSAPI_IPTOS:
668-
if (optlen != sizeof(int)) {
668+
if (optlen != sizeof(u8_t)) {
669669
return NSAPI_ERROR_UNSUPPORTED;
670670
}
671671
s->conn->pcb.ip->tos = (u8_t)(*(const int *)optval);

connectivity/netsocket/include/netsocket/nsapi_types.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,50 @@ extern "C" {
2727
#endif
2828

2929

30+
/*
31+
* The Type of Service provides an indication of the abstract
32+
* parameters of the quality of service desired. These parameters are
33+
* to be used to guide the selection of the actual service parameters
34+
* when transmitting a datagram through a particular network. Several
35+
* networks offer service precedence, which somehow treats high
36+
* precedence traffic as more important than other traffic (generally
37+
* by accepting only traffic above a certain precedence at time of high
38+
* load). The major choice is a three way tradeoff between low-delay,
39+
* high-reliability, and high-throughput.
40+
* The use of the Delay, Throughput, and Reliability indications may
41+
* increase the cost (in some sense) of the service. In many networks
42+
* better performance for one of these parameters is coupled with worse
43+
* performance on another. Except for very unusual cases at most two
44+
* of these three indications should be set.
45+
*/
46+
#define NSAPI_IPTOS_TOS_MASK 0x1E
47+
#define NSAPI_IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
48+
#define NSAPI_IPTOS_LOWDELAY 0x10
49+
#define NSAPI_IPTOS_THROUGHPUT 0x08
50+
#define NSAPI_IPTOS_RELIABILITY 0x04
51+
#define NSAPI_IPTOS_LOWCOST 0x02
52+
#define NSAPI_IPTOS_MINCOST IPTOS_LOWCOST
53+
54+
/*
55+
* The Network Control precedence designation is intended to be used
56+
* within a network only. The actual use and control of that
57+
* designation is up to each network. The Internetwork Control
58+
* designation is intended for use by gateway control originators only.
59+
* If the actual use of these precedence designations is of concern to
60+
* a particular network, it is the responsibility of that network to
61+
* control the access to, and use of, those precedence designations.
62+
*/
63+
#define NSAPI_IPTOS_PREC_MASK 0xe0
64+
#define NSAPI_IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
65+
#define NSAPI_IPTOS_PREC_NETCONTROL 0xe0
66+
#define NSAPI_IPTOS_PREC_INTERNETCONTROL 0xc0
67+
#define NSAPI_IPTOS_PREC_CRITIC_ECP 0xa0
68+
#define NSAPI_IPTOS_PREC_FLASHOVERRIDE 0x80
69+
#define NSAPI_IPTOS_PREC_FLASH 0x60
70+
#define NSAPI_IPTOS_PREC_IMMEDIATE 0x40
71+
#define NSAPI_IPTOS_PREC_PRIORITY 0x20
72+
#define NSAPI_IPTOS_PREC_ROUTINE 0x00
73+
3074
/** Enum of standardized error codes
3175
*
3276
* Valid error codes have negative values and may

0 commit comments

Comments
 (0)