title: Receiving USSD Messages not working on Windows Mobile 6.5 HSDPA Devices (Opennetcf.Telephony)
body: <p>I've been using OpenNetCF.Telephony (available here <a href="http://tapi.codeplex.com" rel="nofollow">http://tapi.codeplex.com</a>), with this wrapper is pretty easy to use TAPI to send and receive USSD messages; until now I had been using it with many GSM devices and it worked flawlessy!!!</p>
  
  <p>Recently I tested my program on a Motorola MC65 and ES400, both 3.5G HSDPA devices, and was able to send my USSD request without any problem, but the response doesnt get caught by the read message function; the strange thing is that it's the same code that has worked perfectly in all other GSM devices I have worked with, since USSD shows up a pop up window when it responds, I know that the Carrier's server is responding pretty quickly but my LineGetMessage call hits the timeout without noticing that the response was received...</p>
  
  <p>Here is an extract of a little sample I made to test the functionality, it can be tested anywhere since any carrier's platform would respond with an "UNKNOWN APPLICATION" or similar message if it isn't expecting the message sent, but even this response doesn't get caught...</p>
  
  <pre><code>        private void btnUSSDSend_Click(object sender, EventArgs e)
      {
          int ret = 0; 
          for (int i = 0; i &lt; m_tapi.NumberOfDevices; i++)
          {
  
              DeviceCapabilities dc = new DeviceCapabilities(LINE_DEV_CAPS_INITIAL_SIZE); //LINEDEVCAPS
              dc.Store(); 
              int dwVersion = m_tapi.NegotiateVersion(i);
              ret = NativeMethods.lineGetDevCaps(m_tapi.hLineApp, i, dwVersion, 0, dc.Data); //NativeTapi.lineGetDevCaps
              if (ret &lt; 0)
              {
                  MessageBox.Show(((ErrorCode)ret).ToString()); //LINEERR
              }
  
              if ((ErrorCode)ret == ErrorCode.StructureTooSmall)  //LINEERR  STRUCTURETOOSMALL
              {
                  dc.Data = new byte[dc.NeededSize]; //dc.dwNeededSize
                  ret = NativeMethods.lineGetDevCaps(m_tapi.hLineApp, i, dwVersion, 0, dc.Data); //NativeTapi
              }
  
              dc.Load();
  
              DeviceCaps.Add( i, dc);
  
              AddressStatus ac = new AddressStatus(1024);
              ac.Store();
              ret = NativeMethods.lineGetAddressCaps(m_tapi.hLineApp, i, 0, dwVersion, 0, ac.Data); //NativeTapi
              ac.Load();
              ac = null;
  
          }
  
  
          bool found = false;
          foreach (KeyValuePair&lt;int, DeviceCapabilities&gt; entry in DeviceCaps) //LINEDEVCAPS
          {
              DeviceCapabilities dc = entry.Value;  //LINEDEVCAPS 
              found = true;
              if (dc != null &amp;&amp; dc.ProviderName.StartsWith(NativeMethods.CELLTSP_PROVIDERINFO_STRING)) //CellTSP.CELLTSP_PROVIDERINFO_STRING
              {
                  m_line = m_tapi.CreateLine(entry.Key,  MediaMode.DataModem  | MediaMode.InteractiveVoice, CallPrivilege.Monitor |CallPrivilege.Owner ); //LINEMEDIAMODE LINECALLPRIVILEGE
  
                  byte[] dialArray; 
                  LineMessage msg; //LINEMESSAGE
                  int flags = 0;
                  byte[] chResponse;
                  string Mensaje="";
                  string dial = "*888#";
                  int continuetonext = 0;
              needtosendanother:
                  dialArray= Encoding.Unicode.GetBytes(dial);
                  int length = dialArray.Length;
                  int result = NativeMethods.lineSendUSSD(m_line.hLine, dialArray, dialArray.Length, 0); 
                  AddMessage(dial, 0);
  
  
                  while ( NativeMethods.lineGetMessage(m_tapi.hLineApp, out msg,10000)==0 ) //NativeTapi
                  { 
                      if (msg.MessageID == LineMessages.LINE_DEVSPECIFIC &amp;&amp; (int)(msg.Param1) == (int)LineMessages.LINE_USSD) //msg.dwMessageID | LINEMESSAGES | LINEDEVSPECIFIC_CELLTSP
                      {
                          flags = 0;
                          chResponse = new byte[(int)(msg.Param3)]; //msg.dwParam3
                          result = NativeMethods.lineGetUSSD(m_line.hLine, (int)(msg.Param2), chResponse, chResponse.Length, out flags); 
                          Mensaje = Encoding.Unicode.GetString(chResponse, 0, chResponse.Length);
                          AddMessage(Mensaje, 1);
                          break;
                      }
                  }
                  //in case I have to respond to another message
                  if (Mensaje.ToUpper().Contains("ENTER PIN:"))
                  {
                      continuetonext = 1;
                      dial = "1234";
                  }
                  //some more conditions here...
                  //
                  if (Mensaje.ToUpper().Contains("TRANSFERED"))
                  {
                      continuetonext = 0;
                      dial = "TRANSFERED";
                  }
                  if (Mensaje.ToUpper().Contains("FAILED") || Mensaje.ToUpper().Contains("ERROR"))
                  {
                      continuetonext = 0;
                      dial = "ERROR";
                  }
                  if (continuetonext==1) goto needtosendanother;
              }
  
          }
  
          if (!found)
          {
              MessageBox.Show("Error - line not found");
              return;
          }
      }
  </code></pre>
  
  <p>This is the code that doesn't get a response, it hits the timeout every time :( </p>
  
  <p><strong>while ( NativeMethods.lineGetMessage(m_tapi.hLineApp, out msg,10000)==0 )</strong></p>
  
  <p>I know I have initialized the TAPI right since I have sent the parameter to register for events, actually it manages to receive a  confirmation Linemessage from sending the USSD request which is handled by another thread instantiated in the TAPI wrapper, but the event of the actual response is never raised in these devices.</p>
  
  <p>Is there a change that has to be done in order to get 3/3.5G devices to work? I've been comparing everything that the 2G devices do (with the code), everything seems to work exactly the same, just reading the response is the problem, I really don't have any clue of how to make it work...</p>
  
  <p>Thanks in advance for any other ideas to try or parameters to change...</p>