tty: n_gsm: fix redundant assignment of gsm->encoding
PATCH v2 1/9 tty: n_gsm: fix redundant assignment of gsm->encoding
From: Daniel Starke <[email protected]>
The function gsmld_open() contains a redundant assignment of gsm->encoding. The same value of GSM_ADV_OPT is already assigned to it during the initialization of the struct in gsm_alloc_mux() a few lines earlier.
Fix this by removing the redundant second assignment of gsm->encoding in gsmld_open().
--- drivers/tty/n_gsm.c | 1 - 1 file changed, 1 deletion(-)
v1 -> v2:
Added Reviewed-by tag.
drivers/tty/n_gsm.c +0 -1
@@ -3585,7 +3585,6 @@ static int gsmld_open(struct tty_struct *tty) tty->receive_room =65536 ;/* Attach the initial passive connection */ - gsm->encoding =GSM_ADV_OPT ;gsmld_attach_gsm (tty, gsm);/* The mux will not be activated yet, we wait for correct
Signature · 1 line
2.34.1
PATCH v2 3/9 tty: n_gsm: add missing description to gsm_config
From: Daniel Starke <[email protected]>
Currently, all available structure fields in gsmmux.h except those for gsm_config are commented.
Fix this by adding appropriate comments to the not commented fields. Note that 'mru' and 'mtu' refer to the size without basic/advanced option mode header and byte stuffing as defined in the standard in chapter 5.7.2.
--- include/uapi/linux/gsmmux.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
v1 -> v2:
Added remark regarding the mru/mtu size comment as this was unclear in the review.
include/uapi/linux/gsmmux.h +11 -11
@@ -8,17 +8,17 @@struct gsm_config { -unsigned int adaption; -unsigned int encapsulation; -unsigned int initiator; -unsigned int t1; -unsigned int t2; -unsigned int t3; -unsigned int n2; -unsigned int mru; -unsigned int mtu; -unsigned int k; -unsigned int i; +unsigned int adaption;/* Convergence layer type */ +unsigned int encapsulation;/* Framing (0 = basic option, 1 = advanced option) */ +unsigned int initiator;/* Initiator or responder */ +unsigned int t1;/* Acknowledgment timer */ +unsigned int t2;/* Response timer for multiplexer control channel */ +unsigned int t3;/* Response timer for wake-up procedure */ +unsigned int n2;/* Maximum number of retransmissions */ +unsigned int mru;/* Maximum incoming frame payload size */ +unsigned int mtu;/* Maximum outgoing frame payload size */ +unsigned int k;/* Window size */ +unsigned int i;/* Frame type (1 = UIH, 2 = UI) */ unsigned int unused[8 ];/* Can not be used */ };
Signature · 1 line
2.34.1
PATCH v2 4/9 tty: n_gsm: remove unneeded initialization of ret in gsm_dlci_config
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
The variable 'ret' is not used before assignment from gsm_activate_mux(). Still it gets initialized to zero at declaration.
Fix this as remarked in the link below by moving the declaration to the first assignment.
--- drivers/tty/n_gsm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
v1 -> v2:
Removed Fixed tag in commit message as remarked in the review. Moved 'ret' declaration to the point of the assignment and changed commit message accordingly. This was done as suggested in the review.
drivers/tty/n_gsm.c +1 -2
@@ -3276,7 +3276,6 @@ static void gsm_copy_config_values(struct gsm_mux *gsm,static int gsm_config (struct gsm_mux *gsm,struct gsm_config *c) { -int ret =0 ;int need_close =0 ;int need_restart =0 ;
@@ -3355,7 +3354,7 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c)* and removing from the mux array */ if (gsm->dead) { - ret =gsm_activate_mux (gsm); +int ret =gsm_activate_mux (gsm);if (ret)return ret;if (gsm->initiator)
Signature · 1 line
2.34.1
PATCH v2 6/9 tty: n_gsm: increase malformed counter for malformed control frames
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
The malformed counter in gsm_mux is already increased in case of errors detected in gsm_queue() and gsm1_receive(). gsm_dlci_command() also detects a case for a malformed frame but does not increase the malformed counter yet.
Fix this by also increasing the gsm_mux malformed counter in case of a malformed frame in gsm_dlci_command().
Note that the malformed counter is not yet exposed and only set internally.
--- drivers/tty/n_gsm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
v1 -> v2:
Added remark to the commit message that the malformed counter is not yet exposed to the user. This was remarked in the review.
drivers/tty/n_gsm.c +3 -1
@@ -2454,8 +2454,10 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len) data += dlen;/* Malformed command? */ -if (clen > len) +if (clen > len) { + dlci->gsm->malformed++;return ; + }if (command &1 )gsm_control_message (dlci->gsm, command, data, clen);
Signature · 1 line
2.34.1
PATCH v2 5/9 tty: n_gsm: add open_error counter to gsm_mux
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
Extend the n_gsm link statistics by a failed link open counter in preparation for an upcoming patch which will expose these. This counter is increased whenever an attempt to open the control channel failed. This is true in the following cases:
- new DLCI allocation failed
- connection request (SAMB) with invalid CR flag has been received
- connection response (UA) timed out
- parameter negotiation timed out or failed
--- drivers/tty/n_gsm.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
v1 -> v2:
A cleanup of gsm_control_negotiation() remains open as this exceeds the purpose of this change.
The commit message was extended by more details about the statistics counter cases as remarked in the review.
drivers/tty/n_gsm.c +26 -7
@@ -338,6 +338,7 @@ struct gsm_mux {unsigned long bad_fcs;unsigned long malformed;unsigned long io_error; +unsigned long open_error;unsigned long bad_size;unsigned long unsupported; };
@@ -1729,25 +1730,32 @@ static void gsm_control_negotiation(struct gsm_mux *gsm, unsigned int cr,struct gsm_dlci *dlci;struct gsm_dlci_param_bits *params; -if (dlen <sizeof (struct gsm_dlci_param_bits )) +if (dlen <sizeof (struct gsm_dlci_param_bits )) { + gsm->open_error++;return ; + }/* Invalid DLCI? */ params = (struct gsm_dlci_param_bits *)data; addr =FIELD_GET (PN_D_FIELD_DLCI , params->d_bits); -if (addr ==0 || addr >=NUM_DLCI || !gsm->dlci[addr]) +if (addr ==0 || addr >=NUM_DLCI || !gsm->dlci[addr]) { + gsm->open_error++;return ; + } dlci = gsm->dlci[addr];/* Too late for parameter negotiation? */ -if ((!cr && dlci->state ==DLCI_OPENING ) || dlci->state ==DLCI_OPEN ) +if ((!cr && dlci->state ==DLCI_OPENING ) || dlci->state ==DLCI_OPEN ) { + gsm->open_error++;return ; + }/* Process the received parameters */ if (gsm_process_negotiation (gsm, addr, cr, params) !=0 ) {/* Negotiation failed. Close the link. */ if (debug &DBG_ERRORS )pr_info ("%s PN failed\n" , __func__); + gsm->open_error++;gsm_dlci_close (dlci);return ; }
@@ -1767,6 +1775,7 @@ static void gsm_control_negotiation(struct gsm_mux *gsm, unsigned int cr, }else {if (debug &DBG_ERRORS )pr_info ("%s PN in invalid state\n" , __func__); + gsm->open_error++; } }
@@ -2220,6 +2229,7 @@ static void gsm_dlci_t1(struct timer_list *t) dlci->retries--;mod_timer (&dlci->t1, jiffies + gsm->t1 *HZ /100 ); }else { + gsm->open_error++;gsm_dlci_begin_close (dlci);/* prevent half open link */ }break ;
@@ -2235,6 +2245,7 @@ static void gsm_dlci_t1(struct timer_list *t) dlci->mode =DLCI_MODE_ADM ;gsm_dlci_open (dlci); }else { + gsm->open_error++;gsm_dlci_begin_close (dlci);/* prevent half open link */ }
@@ -2756,12 +2767,16 @@ static void gsm_queue(struct gsm_mux *gsm)switch (gsm->control) {case SABM |PF : -if (cr ==1 ) +if (cr ==1 ) { + gsm->open_error++; goto invalid; + }if (dlci ==NULL ) dlci =gsm_dlci_alloc (gsm, address); -if (dlci ==NULL ) +if (dlci ==NULL ) { + gsm->open_error++;return ; + }if (dlci->dead)gsm_response (gsm, address,DM |PF );else {
@@ -3753,8 +3768,10 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, dlci = gsm->dlci[dc.channel];if (!dlci) { dlci =gsm_dlci_alloc (gsm, dc.channel); -if (!dlci) +if (!dlci) { + gsm->open_error++;return -ENOMEM ; + } }gsm_dlci_copy_config_values (dlci, &dc);if (copy_to_user ((void __user *)arg, &dc,sizeof (dc)))
@@ -3768,8 +3785,10 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, dlci = gsm->dlci[dc.channel];if (!dlci) { dlci =gsm_dlci_alloc (gsm, dc.channel); -if (!dlci) +if (!dlci) { + gsm->open_error++;return -ENOMEM ; + } }return gsm_dlci_config (dlci, &dc,0 );default :
Signature · 1 line
2.34.1
PATCH v2 8/9 tty: n_gsm: cleanup gsm_control_command and gsm_control_reply
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
There are multiple places in gsm_control_command and gsm_control_reply that derive the specific DLCI handle directly out of the DLCI table in gsm.
Add a local variable which holds this handle and use it instead to improve code readability.
--- drivers/tty/n_gsm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
v1 -> v2:
Moved from patch 9 to 8 as suggested in the review.
drivers/tty/n_gsm.c +6 -4
@@ -1450,15 +1450,16 @@ static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, int dlen) {struct gsm_msg *msg; +struct gsm_dlci *dlci = gsm->dlci[0 ]; - msg =gsm_data_alloc (gsm,0 , dlen +2 , gsm->dlci[0 ]->ftype); + msg =gsm_data_alloc (gsm,0 , dlen +2 , dlci->ftype);if (msg ==NULL )return -ENOMEM ; msg->data[0 ] = (cmd <<1 ) |CR |EA ;/* Set C/R */ msg->data[1 ] = (dlen <<1 ) |EA ;memcpy (msg->data +2 , data, dlen); -gsm_data_queue (gsm->dlci[0 ], msg); +gsm_data_queue (dlci, msg);return 0 ; }
@@ -1477,14 +1478,15 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, int dlen) {struct gsm_msg *msg; +struct gsm_dlci *dlci = gsm->dlci[0 ]; - msg =gsm_data_alloc (gsm,0 , dlen +2 , gsm->dlci[0 ]->ftype); + msg =gsm_data_alloc (gsm,0 , dlen +2 , dlci->ftype);if (msg ==NULL )return ; msg->data[0 ] = (cmd &0xFE ) <<1 |EA ;/* Clear C/R */ msg->data[1 ] = (dlen <<1 ) |EA ;memcpy (msg->data +2 , data, dlen); -gsm_data_queue (gsm->dlci[0 ], msg); +gsm_data_queue (dlci, msg); }/**
Signature · 1 line
2.34.1
PATCH v2 9/9 tty: n_gsm: add DLCI specific rx/tx statistics
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
Add counters for the number of data bytes received/transmitted per DLCI in for preparation for an upcoming patch which will expose these values to the user.
--- drivers/tty/n_gsm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
v1 -> v2:
Moved from patch 8 to 9 as suggested in the review.
Added missing change of gsm_dlci_data_output_framed() where dlci->tx also needs to be increased. This has been pointed out in the review.
drivers/tty/n_gsm.c +24 -1
@@ -185,6 +185,9 @@ struct gsm_dlci {void (*data)(struct gsm_dlci *dlci,const u8 *data,int len);void (*prev_data)(struct gsm_dlci *dlci,const u8 *data,int len);struct net_device *net;/* network interface, if created */ +/* Statistics (not currently exposed) */ +u64 tx;/* Data bytes sent on this DLCI */ +u64 rx;/* Data bytes received on this DLCI */ };/*
@@ -1215,6 +1218,7 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)tty_port_tty_wakeup (&dlci->port);__gsm_data_queue (dlci, msg); + dlci->tx += len;/* Bytes of data we used up */ return size; }
@@ -1282,6 +1286,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,memcpy (dp, dlci->skb->data, len);skb_pull (dlci->skb, len);__gsm_data_queue (dlci, msg); + dlci->tx += len;if (last) {dev_kfree_skb_any (dlci->skb); dlci->skb =NULL ;
@@ -1460,6 +1465,7 @@ static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, msg->data[1 ] = (dlen <<1 ) |EA ;memcpy (msg->data +2 , data, dlen);gsm_data_queue (dlci, msg); + dlci->tx += dlen;return 0 ; }
@@ -1487,6 +1493,7 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, msg->data[1 ] = (dlen <<1 ) |EA ;memcpy (msg->data +2 , data, dlen);gsm_data_queue (dlci, msg); + dlci->tx += dlen; }/**
@@ -1851,10 +1858,13 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, const u8 *data, int clen) {u8 buf[1 ]; +struct gsm_dlci *dlci = gsm->dlci[0 ]; + +if (dlci) + dlci->rx += clen;switch (command) {case CMD_CLD : { -struct gsm_dlci *dlci = gsm->dlci[0 ];/* Modem wishes to close down */ if (dlci) { dlci->dead = true;
@@ -1933,6 +1943,8 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, ctrl = gsm->pending_cmd; dlci = gsm->dlci[0 ]; +if (dlci) + dlci->rx += clen; command |=1 ;/* Does the reply match our command */ if (ctrl !=NULL && (command == ctrl->cmd || command ==CMD_NSC )) {
@@ -2297,6 +2309,9 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlci) need_pn = true; } + dlci->tx =0 ; + dlci->rx =0 ; +switch (dlci->state) {case DLCI_CLOSED :case DLCI_WAITING_CONFIG :
@@ -2329,6 +2344,9 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlci)*/ static void gsm_dlci_set_opening (struct gsm_dlci *dlci) { + dlci->tx =0 ; + dlci->rx =0 ; +switch (dlci->state) {case DLCI_CLOSED :case DLCI_WAITING_CONFIG :
@@ -2348,6 +2366,9 @@ static void gsm_dlci_set_opening(struct gsm_dlci *dlci)*/ static void gsm_dlci_set_wait_config (struct gsm_dlci *dlci) { + dlci->tx =0 ; + dlci->rx =0 ; +switch (dlci->state) {case DLCI_CLOSED :case DLCI_CLOSING :
@@ -2424,6 +2445,7 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) fallthrough;case 1 :/* Line state will go via DLCI 0 controls only */ default : + dlci->rx += clen;tty_insert_flip_string (port, data, clen);tty_flip_buffer_push (port); }
@@ -2784,6 +2806,7 @@ static void gsm_queue(struct gsm_mux *gsm) gsm->open_error++;return ; } + dlci->rx += gsm->len;if (dlci->dead)gsm_response (gsm, address,DM |PF );else {
Signature · 1 line
2.34.1
PATCH v2 2/9 tty: n_gsm: add restart parameter to DLC specific ioctl config
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
Currently, changing the parameters of a DLCI gives no direct control to the user whether this should trigger a channel reset or not. The decision is solely made by the driver based on the assumption which parameter changes are compatible or not. Therefore, the user has no means to perform an automatic channel reset after parameter configuration for non-conflicting changes.
Add the parameter 'restart' to 'gsm_dlci_config' to force a channel reset after ioctl setting regardless of whether the changes made require this or not.
Note that the parameter is limited to the values 0 and 1 to allow future additions here.
--- drivers/tty/n_gsm.c | 4 ++++ include/uapi/linux/gsmmux.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
v1 -> v2:
Changed wording as remarked in the review.
drivers/tty/n_gsm.c +4 -0
@@ -2531,6 +2531,8 @@ static int gsm_dlci_config(struct gsm_dlci *dlci, struct gsm_dlci_config *dc, inreturn -EINVAL ;if (dc->k >7 )return -EINVAL ; +if (dc->restart >1 )/* allow future extensions */ +return -EINVAL ;/* * See what is needed for reconfiguration
@@ -2545,6 +2547,8 @@ static int gsm_dlci_config(struct gsm_dlci *dlci, struct gsm_dlci_config *dc, in/* Requires care */ if (dc->priority != dlci->prio) need_restart = true; +if (dc->restart) + need_restart = true;if ((open && gsm->wait_config) || need_restart) need_open = true;
include/uapi/linux/gsmmux.h +2 -1
@@ -58,7 +58,8 @@ struct gsm_dlci_config {__u32 priority;/* Priority (0 for default value) */ __u32 i;/* Frame type (1 = UIH, 2 = UI) */ __u32 k;/* Window size (0 for default value) */ -__u32 reserved[8 ];/* For future use, must be initialized to zero */ +__u32 restart;/* Force DLCI channel reset? */ +__u32 reserved[7 ];/* For future use, must be initialized to zero */ };#define GSMIOC_GETCONF_DLCI _IOWR('G', 7, struct gsm_dlci_config)
Signature · 1 line
2.34.1
PATCH v2 7/9 tty: n_gsm: increase gsm_mux unsupported counted where appropriate
In reply to D. StarkeFrom: Daniel Starke <[email protected]>
The structure gsm_mux contains the 'unsupported' field. However, there is currently no place in the code which increases this counter.
Increase the 'unsupported' statistics counter in the following case:
- an unsupported frame type has been requested by the peer via parameter negotiation
- a control frame with an unsupported but known command has been received
Note that we have no means to detect an inconsistent/unsupported adaptation sufficient accuracy as this changes the structure of the UI/UIH frames. E.g. a one byte header is added in case of convergence layer type 2 instead of 1 and contains the modem signal octet with the state of the signal lines. There is no checksum or other value which indicates of this field is correct or should be present. Therefore, we can only assume protocol correctness here. See also 'gsm_dlci_data()' where this is handled.
--- drivers/tty/n_gsm.c | 3 +++ 1 file changed, 3 insertions(+)
v1 -> v2:
Added details about missing detection of inconsistent/unsupported adaption to the commit message. A question about this came up during the review.
drivers/tty/n_gsm.c +3 -0
@@ -1589,6 +1589,7 @@ static int gsm_process_negotiation(struct gsm_mux *gsm, unsigned int addr,if (debug &DBG_ERRORS )pr_info ("%s unsupported I frame request in PN\n" , __func__); + gsm->unsupported++;return -EINVAL ;default :if (debug &DBG_ERRORS )
@@ -1896,6 +1897,8 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command,/* Optional unsupported commands */ case CMD_RPN :/* Remote port negotiation */ case CMD_SNC :/* Service negotiation command */ + gsm->unsupported++; + fallthrough;default :/* Reply to bad commands with an NSC */ buf[0 ] = command;
Signature · 1 line
2.34.1
Jiri Slaby
maintainerRe: [PATCH v2 3/9] tty: n_gsm: add missing description to gsm_config
In reply to D. StarkeQuoted 8 lines · D. Starke
From: Daniel Starke <[email protected]>
Currently, all available structure fields in
gsmmux.hexcept those forgsm_configare commented.Fix this by adding appropriate comments to the not commented fields. Note that 'mru' and 'mtu' refer to the size without basic/advanced option mode header and byte stuffing as defined in the standard in chapter 5.7.2.
Maybe you can start documenting them using kernel-doc? And convert the others and expose them all to Documentation and finally to:
https://www.kernel.org/doc/html/latest/
?
Quoted 45 lines
Link https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516Signed-off-by Daniel Starke <[email protected]>--- include/uapi/linux/gsmmux.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)v1 -> v2:
Added remark regarding the mru/mtu size comment as this was unclear in the review.include/uapi/linux/gsmmux.h +11
-11@@ -8,17 +8,17 @@struct gsm_config { -unsigned int adaption; -unsigned int encapsulation; -unsigned int initiator; -unsigned int t1; -unsigned int t2; -unsigned int t3; -unsigned int n2; -unsigned int mru; -unsigned int mtu; -unsigned int k; -unsigned int i; +unsigned int adaption;/* Convergence layer type */ +unsigned int encapsulation;/* Framing (0 = basic option, 1 = advanced option) */ +unsigned int initiator;/* Initiator or responder */ +unsigned int t1;/* Acknowledgment timer */ +unsigned int t2;/* Response timer for multiplexer control channel */ +unsigned int t3;/* Response timer for wake-up procedure */ +unsigned int n2;/* Maximum number of retransmissions */ +unsigned int mru;/* Maximum incoming frame payload size */ +unsigned int mtu;/* Maximum outgoing frame payload size */ +unsigned int k;/* Window size */ +unsigned int i;/* Frame type (1 = UIH, 2 = UI) */ unsigned int unused[8 ];/* Can not be used */ };
Signature · 2 lines
js suse labs
Greg KH
maintainerRe: [PATCH v2 3/9] tty: n_gsm: add missing description to gsm_config
Quoted 6 lines · Jiri Slaby
Quoted 5 lines · D. Starke
From: Daniel Starke <[email protected]>
Currently, all available structure fields in
gsmmux.hexcept those forgsm_configare commented.
Quoted 8 lines
Quoted 3 lines
Fix this by adding appropriate comments to the not commented fields. Note that 'mru' and 'mtu' refer to the size without basic/advanced option mode header and byte stuffing as defined in the standard in chapter 5.7.2.
Maybe you can start documenting them using kernel-doc? And convert the others and expose them all to Documentation and finally to:
https://www.kernel.org/doc/html/latest/
?
I agree, this should be done in kerneldoc format please.
thanks,
greg k-h