faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
388 stars 304 forks source link

Odd ordering of AT response breaks USSD #13

Closed faucamp closed 11 years ago

faucamp commented 11 years ago

I received the following report via email from Jonathan Endersby: (edited to remove service identifiers since I'm not sure how sensitive the info is)

I'm working on something that simulates USSD traffic and have picked up a "bug" in gsmmodem that is probably quite easy to fix. I say "bug" because really it's probably the modem doing something non-3gpp compliant (What a surprise right?)

Basically I have a USSD conversation and everything goes well except sometimes I receive my "+CUSD" before my "OK", which confuses gsmmodem and it gets a timeout.

I suspect it is ignoring the +CUSD thinking it is an "OK" and then waiting for an "+CUSD" when all it ever receives is an "OK".

.AT+CUSD=1,"_111_11111#",15

.OK . .+CUSD: 1,"What would you like to search for?",0 .AT+CUSD=1,"Test Answer",15

.OK . .+CUSD: 1,"1. Option 1.2. Another option",0 .AT+CUSD=1,"1",15

.OK . .+CUSD: 1,"1. Heading.2. First section.3. Second section.",0 .AT+CUSD=1,"2",15

.+CUSD: 0,"Lorem ipsum blah blah ....",15 . .OK

Notice how that the last +CUSD arrived before it's "OK".

faucamp commented 11 years ago

Issue confirmed; this is fairly strange modem behaviour... but it has also exposed a secondary bug that could cause the sendUssd() command to timeout if the +CUSD response is received too quickly after the OK acknowledgment (due to an implicit race condition with the thread lock mechanism).