diff options
Diffstat (limited to 'drivers/isdn/gigaset/isocdata.c')
-rw-r--r-- | drivers/isdn/gigaset/isocdata.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c index 85394a6ebae8..16fd3bd48883 100644 --- a/drivers/isdn/gigaset/isocdata.c +++ b/drivers/isdn/gigaset/isocdata.c | |||
@@ -905,29 +905,49 @@ void gigaset_isoc_receive(unsigned char *src, unsigned count, | |||
905 | 905 | ||
906 | /* == data input =========================================================== */ | 906 | /* == data input =========================================================== */ |
907 | 907 | ||
908 | /* process a block of received bytes in command mode (mstate != MS_LOCKED) | ||
909 | * Append received bytes to the command response buffer and forward them | ||
910 | * line by line to the response handler. | ||
911 | * Note: Received lines may be terminated by CR, LF, or CR LF, which will be | ||
912 | * removed before passing the line to the response handler. | ||
913 | */ | ||
908 | static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf) | 914 | static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf) |
909 | { | 915 | { |
910 | struct cardstate *cs = inbuf->cs; | 916 | struct cardstate *cs = inbuf->cs; |
911 | unsigned cbytes = cs->cbytes; | 917 | unsigned cbytes = cs->cbytes; |
918 | unsigned char c; | ||
912 | 919 | ||
913 | while (numbytes--) { | 920 | while (numbytes--) { |
914 | /* copy next character, check for end of line */ | 921 | c = *src++; |
915 | switch (cs->respdata[cbytes] = *src++) { | 922 | switch (c) { |
916 | case '\r': | ||
917 | case '\n': | 923 | case '\n': |
918 | /* end of line */ | 924 | if (cbytes == 0 && cs->respdata[0] == '\r') { |
919 | gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", | 925 | /* collapse LF with preceding CR */ |
920 | __func__, cbytes); | 926 | cs->respdata[0] = 0; |
921 | if (cbytes >= MAX_RESP_SIZE - 1) | 927 | break; |
922 | dev_warn(cs->dev, "response too large\n"); | 928 | } |
929 | /* --v-- fall through --v-- */ | ||
930 | case '\r': | ||
931 | /* end of message line, pass to response handler */ | ||
932 | if (cbytes >= MAX_RESP_SIZE) { | ||
933 | dev_warn(cs->dev, "response too large (%d)\n", | ||
934 | cbytes); | ||
935 | cbytes = MAX_RESP_SIZE; | ||
936 | } | ||
923 | cs->cbytes = cbytes; | 937 | cs->cbytes = cbytes; |
938 | gigaset_dbg_buffer(DEBUG_TRANSCMD, "received response", | ||
939 | cbytes, cs->respdata); | ||
924 | gigaset_handle_modem_response(cs); | 940 | gigaset_handle_modem_response(cs); |
925 | cbytes = 0; | 941 | cbytes = 0; |
942 | |||
943 | /* store EOL byte for CRLF collapsing */ | ||
944 | cs->respdata[0] = c; | ||
926 | break; | 945 | break; |
927 | default: | 946 | default: |
928 | /* advance in line buffer, checking for overflow */ | 947 | /* append to line buffer if possible */ |
929 | if (cbytes < MAX_RESP_SIZE - 1) | 948 | if (cbytes < MAX_RESP_SIZE) |
930 | cbytes++; | 949 | cs->respdata[cbytes] = c; |
950 | cbytes++; | ||
931 | } | 951 | } |
932 | } | 952 | } |
933 | 953 | ||
@@ -958,8 +978,6 @@ void gigaset_isoc_input(struct inbuf_t *inbuf) | |||
958 | numbytes, src); | 978 | numbytes, src); |
959 | gigaset_if_receive(inbuf->cs, src, numbytes); | 979 | gigaset_if_receive(inbuf->cs, src, numbytes); |
960 | } else { | 980 | } else { |
961 | gigaset_dbg_buffer(DEBUG_CMD, "received response", | ||
962 | numbytes, src); | ||
963 | cmd_loop(src, numbytes, inbuf); | 981 | cmd_loop(src, numbytes, inbuf); |
964 | } | 982 | } |
965 | 983 | ||