NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Revision:
2:a4f97773c90f
Parent:
0:632c9925f013
--- a/drv/serial/usb/usbserialif.cpp	Mon Jun 14 10:33:54 2010 +0000
+++ b/drv/serial/usb/usbserialif.cpp	Fri Jun 18 09:22:54 2010 +0000
@@ -35,9 +35,15 @@
 UsbEndpoint* pEpIn;
 UsbEndpoint* pEpOut;
 
-USB_INT08U ser_int_found;
+#define DONGLE_STATE_UNKNOWN 0
+#define DONGLE_STATE_CDFS    1
+#define DONGLE_STATE_SERIAL  2
+
+USB_INT08U dongleState;
+
 USB_INT32S SerialInit()
 {
+  dongleState = DONGLE_STATE_UNKNOWN;
   Host_Init();               // Initialize the  host controller
   USB_INT32S rc = Host_EnumDev();       // Enumerate the device connected
   if (rc != OK)
@@ -50,7 +56,7 @@
 
 bool SerialHasToSwitch()
 {
-  return (ser_int_found == 3);
+  return (dongleState == DONGLE_STATE_CDFS);
 }
 
 uint16_t m_vid;
@@ -61,7 +67,7 @@
   bool scsi = false;
   //Size 31
   const unsigned char magicHuawei[] = { 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0,    0, 0, 0, 0,    0, 0,    0x11, 0x6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-  const unsigned char magicVoda[] = {   0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12, 0x01, 0, 0, 0, 0x80, 0, 0x06, 0x01, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+  const unsigned char magicVoda[]   = { 0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12, 0x01, 0, 0, 0, 0x80, 0, 0x06, 0x01, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
   char* magic;
   USB_INT32S rc;
   if((m_vid == 0x12d1) && (m_pid == 0x1446))
@@ -86,20 +92,15 @@
    return -1;
   }
   
-  
   if(scsi)
   {
-    //rc = Host_ProcessTD(EDBulkOut, TD_OUT, (volatile USB_INT08U*)magic, 31);
     rc = pEpOut->transfer((volatile USB_INT08U*)magic, 31);
     while(rc == PROCESSING)
     {
-     // __WFI();
       rc = pEpOut->status();
-    }
-  
+    }  
   }
-  
-  
+    
   delete pEpOut;
   pEpOut = NULL;
   return rc;
@@ -125,25 +126,25 @@
       m_pid == 0x1446 )
   {
     PRINT_Log("\r\nHuawei device found in CDFS mode\r\n");
-    ser_int_found=3;
+    dongleState = DONGLE_STATE_CDFS;
   }
   else if(  m_vid == 0x12d1 &&//Huawei : Change
             m_pid == 0x1001 )
   {
     PRINT_Log("\r\nHuawei device found in Serial mode\r\n");
-    ser_int_found=1;
+    dongleState = DONGLE_STATE_SERIAL;
   }
   else if(  m_vid  == 0x0af0 &&//Voda?Qualcomm? : Change
             m_pid == 0x7501 )
   {
     PRINT_Log("\r\nVodafone K3760 found, checking mode...\r\n");
-    ser_int_found=3;
+    dongleState = DONGLE_STATE_UNKNOWN;
   }
   else if(  m_vid  == 0x12d1 &&//Voda?Qualcomm? : Change
             m_pid == 0x1003 )
   {
     PRINT_Log("\r\nHuawei device found, checking mode...\r\n");
-    ser_int_found=3;
+    dongleState = DONGLE_STATE_UNKNOWN;
   }
   else
   {
@@ -176,8 +177,13 @@
                  if (desc_ptr[5] == 0xFF &&             
                      desc_ptr[6] == 0xFF &&     
                      desc_ptr[7] == 0xFF ) {       
-                     //if(ser_int_found==1)
-                     ser_int_found=2;
+                   dongleState = DONGLE_STATE_SERIAL;
+                 }
+                 else 
+                 if (desc_ptr[5] == 0xFF &&             
+                     desc_ptr[6] == 0xFF &&     
+                     desc_ptr[7] == 0xFF ) {       
+                   dongleState = DONGLE_STATE_CDFS;
                  }
                  desc_ptr    += desc_ptr[0];                      /* Move to next descriptor start      */
                  break;
@@ -186,51 +192,13 @@
                  PRINT_Log("\r\nEp %02x of size %d.\r\n", desc_ptr[2], (ReadLE16U(&desc_ptr[4]) ));
                  if ( SerialHasToSwitch() )
                  {
-                   if( pEpOut == NULL /*desc_ptr[2] == 1*/) //EP 1
+                   if( (dongleState == DONGLE_STATE_CDFS) && (pEpOut == NULL) /*desc_ptr[2] == 1*/) //EP 1
                    {
-                   #if 0
-                         EDBulkOut->Control = 1                             |      /* USB address           */
-                                              ((desc_ptr[2] & 0x7F) << 7)   |      /* Endpoint address      */
-                                              (1 << 11)                     |      /* direction             */
-                                              (ReadLE16U(&desc_ptr[4]) << 16);     /* MaxPkt Size           */
-                   #endif
                      pEpOut = new UsbEndpoint((desc_ptr[2] & 0x7F), false, ReadLE16U(&desc_ptr[4]));
                    }
-                   desc_ptr += desc_ptr[0];                     /* Move to next descriptor start      */
+                                      /* Move to next descriptor start      */
                  }
-                 else if ((desc_ptr[3] & 0x03) == 0x02) {                  /* If it is Bulk endpoint             */
-                     if (desc_ptr[2] & 0x80) {                        /* If it is In endpoint               */
-                       if(epIn == 0)
-                       {
-                         PRINT_Log("\r\nEp %02x is in ep.\r\n", desc_ptr[2]);
-                       #if 0
-                         EDBulkIn->Control =  1                             |      /* USB address           */
-                                              ((desc_ptr[2] & 0x7F) << 7)   |      /* Endpoint address      */
-                                              (2 << 11)                     |      /* direction             */
-                                              (ReadLE16U(&desc_ptr[4]) << 16);     /* MaxPkt Size           */
-                       #endif
-                       // pEpIn = new UsbEndpoint((desc_ptr[2] & 0x7F), true, ReadLE16U(&desc_ptr[4]));
-                       }
-                       epIn++;
-                       desc_ptr += desc_ptr[0];                     /* Move to next descriptor start      */
-                     } else {                                         /* If it is Out endpoint              */
-                       if(epOut == 0)
-                       {
-                         PRINT_Log("\r\nEp %02x is out ep.\r\n", desc_ptr[2]);
-                       #if 0
-                         EDBulkOut->Control = 1                             |      /* USB address           */
-                                              ((desc_ptr[2] & 0x7F) << 7)   |      /* Endpoint address      */
-                                              (1 << 11)                     |      /* direction             */
-                                              (ReadLE16U(&desc_ptr[4]) << 16);     /* MaxPkt Size           */
-                       #endif
-                        // pEpOut = new UsbEndpoint((desc_ptr[2] & 0x7F), false, ReadLE16U(&desc_ptr[4]));
-                       }
-                       epOut++;
-                       desc_ptr += desc_ptr[0];                     /* Move to next descriptor start      */
-                     }
-                 } else {                                             /* If it is not bulk end point        */
-                     desc_ptr += desc_ptr[0];                         /* Move to next descriptor start      */
-                 }
+                 desc_ptr += desc_ptr[0];  
                  break;
 
             default:                                 /* If the descriptor is neither interface nor endpoint */
@@ -238,8 +206,8 @@
                  break;
         }
     }
-    if (ser_int_found==2) {
-        PRINT_Log("Virtual Serial Port device %04x:%04x connected, vid=%d, pid=%d, E220=%d\n", m_vid, m_pid, ( m_vid  == 0x12d1 ), ( m_pid == 0x1003 ), (( m_vid  == 0x12d1 ) && ( m_pid == 0x1003 )));
+    if (dongleState == DONGLE_STATE_SERIAL) {
+        PRINT_Log("Virtual Serial Port device %04x:%04x connected, vid=%d, pid=%d\n", m_vid, m_pid);
       if(m_vid==0x0af0) //Voda
       {
         pEpOut = new UsbEndpoint((0x0a & 0x7F), false, 64);
@@ -254,21 +222,6 @@
         pEpIn = new UsbEndpoint((0x82 & 0x7F), true, 64);
         PRINT_Log("Huawei E220\r\n");
       }
-      /*else
-      {
-        if(( m_vid  == 0x12d1 ))
-           PRINT_Log("VID OK\r\n");
-        else
-           PRINT_Log("VID NOK\r\n");
-        if(( m_pid  == 0x1003 ))
-           PRINT_Log("VID OK\r\n");
-        else
-           PRINT_Log("VID NOK\r\n");
-        PRINT_Log("\r\n....\r\n\r\n");
-        error("\r\n\r\n");
-      }*/
-      //} 
-      #if 1
       else /*if (  m_vid  == 0x12d1 &&
             m_pid == 0x1001 )*/
       {
@@ -276,12 +229,11 @@
         pEpIn = new UsbEndpoint((0x82 & 0x7F), true, 64); 
         PRINT_Log("Huawei E1550\r\n");
       }   
-      #endif
         
         PRINT_Log("Virtual Serial Port device %04x:%04x connected\n", m_vid, m_pid);
         return (OK);
     }
-    else if (ser_int_found==3) {
+    else if (dongleState == DONGLE_STATE_CDFS) {
         PRINT_Log("CDFS dongle connected, reset\n");
         return (OK);
     } else {