]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / net / cellular / UbloxUSBModem / UbloxGSMModemInitializer.cpp
1 /* Copyright (c) 2010-2012 mbed.org, MIT License
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 */
18
19 #include "UbloxGSMModemInitializer.h"
20 #include "core/dbg.h"
21
22 #define __DEBUG__ 0
23 #ifndef __MODULE__
24 #define __MODULE__ "UbloxGSMModemInitializer.cpp"
25 #endif
26
27 //-----------------------------------------------------------------------
28 // mamm, u-blox Modem
29 //-----------------------------------------------------------------------
30
31 UbloxGSMModemInitializer::UbloxGSMModemInitializer(USBHost* pHost) : WANDongleInitializer(pHost)
32 {
33   
34 }
35
36 uint16_t UbloxGSMModemInitializer::getMSDVid()      { return 0x1546; }
37 uint16_t UbloxGSMModemInitializer::getMSDPid()      { return 0x0000; }
38
39 uint16_t UbloxGSMModemInitializer::getSerialVid()   { return 0x1546; }
40 uint16_t UbloxGSMModemInitializer::getSerialPid()   { return 0x1102; }
41
42 bool UbloxGSMModemInitializer::switchMode(USBDeviceConnected* pDev)
43 {
44   for (int i = 0; i < pDev->getNbIntf(); i++)
45   {
46     if (pDev->getInterface(i)->intf_class == MSD_CLASS)
47     {
48       USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
49       if ( pEp != NULL ) 
50       {
51         ERR("MSD descriptor found on device %p, intf %d", (void *)pDev, i);
52       }
53     }  
54   }
55   return false;
56 }
57
58 #define UBX_SERIALCOUNT 7 
59
60 int UbloxGSMModemInitializer::getSerialPortCount()
61 {
62   return UBX_SERIALCOUNT;
63 }
64
65 /*virtual*/ void UbloxGSMModemInitializer::setVidPid(uint16_t vid, uint16_t pid)
66 {
67     if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
68     {
69       m_hasSwitched = true;
70       m_currentSerialIntf = 0;
71       m_endpointsToFetch = UBX_SERIALCOUNT*2;
72     }
73     else
74     {
75       m_hasSwitched = false;
76       m_endpointsToFetch = 1;
77     }
78 }
79
80 /*virtual*/ bool UbloxGSMModemInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
81 {
82   if( m_hasSwitched )
83   {
84     DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol);
85     if( intf_class == 0x0A )
86     {
87       if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) )
88       {
89         m_serialIntfMap[m_currentSerialIntf++] = intf_nb;
90         return true;
91       }
92       m_currentSerialIntf++;
93     }
94   }
95   else
96   {
97     if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
98     {
99       return true;
100     }
101   }
102   return false;
103 }
104
105 /*virtual*/ bool UbloxGSMModemInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
106 {
107   if( m_hasSwitched )
108   {
109     DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir);
110     if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
111     {
112       m_endpointsToFetch--;
113       return true;
114     }
115   }
116   else
117   {
118     if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
119     {
120       m_endpointsToFetch--;
121       return true;
122     }
123   }
124   return false;
125 }
126
127 /*virtual*/ int UbloxGSMModemInitializer::getType()
128 {
129   return WAN_DONGLE_TYPE_UBLOX_LISAU200;
130 }
131