local fork (temporary)

Dependents:   VodafoneUSBModem_bleedingedge2

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Committer:
ashleymills
Date:
Wed Jan 09 16:13:34 2013 +0000
Revision:
24:f4b676f61906
Parent:
23:8f2d9a244224
Child:
25:3184f71557bf
Experimental MU509 Support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 10:08bce4cd973a 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
donatien 3:4394986752db 2 *
donatien 3:4394986752db 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 3:4394986752db 4 * and associated documentation files (the "Software"), to deal in the Software without
donatien 3:4394986752db 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
donatien 3:4394986752db 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
donatien 3:4394986752db 7 * Software is furnished to do so, subject to the following conditions:
donatien 3:4394986752db 8 *
donatien 3:4394986752db 9 * The above copyright notice and this permission notice shall be included in all copies or
donatien 3:4394986752db 10 * substantial portions of the Software.
donatien 3:4394986752db 11 *
donatien 3:4394986752db 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 3:4394986752db 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 3:4394986752db 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 3:4394986752db 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 3:4394986752db 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 3:4394986752db 17 */
donatien 3:4394986752db 18
ashleymills 24:f4b676f61906 19 #define __DEBUG__ 0
donatien 3:4394986752db 20 #ifndef __MODULE__
donatien 3:4394986752db 21 #define __MODULE__ "WANDongleInitializer.cpp"
donatien 3:4394986752db 22 #endif
donatien 3:4394986752db 23
donatien 12:a712bad7a979 24 #include "core/dbg.h"
donatien 3:4394986752db 25
donatien 3:4394986752db 26 #include <cstdint>
donatien 3:4394986752db 27 using std::uint16_t;
donatien 3:4394986752db 28
donatien 3:4394986752db 29 #include "WANDongleInitializer.h"
donatien 3:4394986752db 30
donatien 3:4394986752db 31 WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost)
donatien 3:4394986752db 32 {
donatien 3:4394986752db 33
donatien 3:4394986752db 34 }
donatien 3:4394986752db 35
donatien 3:4394986752db 36 WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost)
donatien 3:4394986752db 37 {
donatien 3:4394986752db 38 static VodafoneK3770Initializer vodafoneK3770(pHost);
donatien 8:0d1ec493842c 39 static VodafoneK3772ZInitializer vodafoneK3772Z(pHost);
ashleymills 20:3abcf818be31 40 static VodafoneK3773Initializer vodafoneK3773(pHost);
ashleymills 21:dcc8c866ccbb 41 static VodafoneMU509Initializer vodafoneMU509(pHost);
ashleymills 21:dcc8c866ccbb 42 const static WANDongleInitializer* list[] = {
ashleymills 21:dcc8c866ccbb 43 &vodafoneK3770,
ashleymills 21:dcc8c866ccbb 44 &vodafoneK3772Z,
ashleymills 21:dcc8c866ccbb 45 &vodafoneK3773,
ashleymills 21:dcc8c866ccbb 46 &vodafoneMU509,
ashleymills 21:dcc8c866ccbb 47 NULL
ashleymills 21:dcc8c866ccbb 48 };
donatien 3:4394986752db 49 return (WANDongleInitializer**)list;
donatien 3:4394986752db 50 }
donatien 3:4394986752db 51
donatien 3:4394986752db 52 //Huawei K3770 (Vodafone)
nherriot 5:3189db174f6b 53 // Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 00 11 06 20 00 00 01 00 00 00 00 00 00 00 00 00 00"
donatien 3:4394986752db 54 static uint8_t vodafone_k3770_switch_packet[] = {
donatien 3:4394986752db 55 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x06, 0x20, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
donatien 3:4394986752db 56 };
donatien 3:4394986752db 57
donatien 3:4394986752db 58 VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
donatien 3:4394986752db 59 {
donatien 3:4394986752db 60
donatien 3:4394986752db 61 }
donatien 3:4394986752db 62
donatien 3:4394986752db 63 uint16_t VodafoneK3770Initializer::getMSDVid() { return 0x12D1; }
donatien 3:4394986752db 64 uint16_t VodafoneK3770Initializer::getMSDPid() { return 0x14D1; }
donatien 3:4394986752db 65
donatien 3:4394986752db 66 uint16_t VodafoneK3770Initializer::getSerialVid() { return 0x12D1; }
donatien 3:4394986752db 67 uint16_t VodafoneK3770Initializer::getSerialPid() { return 0x14C9; }
donatien 3:4394986752db 68
donatien 3:4394986752db 69 bool VodafoneK3770Initializer::switchMode(USBDeviceConnected* pDev)
donatien 3:4394986752db 70 {
donatien 3:4394986752db 71 for (int i = 0; i < pDev->getNbInterface(); i++)
donatien 3:4394986752db 72 {
donatien 3:4394986752db 73 if (pDev->getInterface(i)->intf_class == MSD_CLASS)
donatien 3:4394986752db 74 {
donatien 9:c9e9817c398c 75 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
donatien 3:4394986752db 76 if ( pEp != NULL )
donatien 3:4394986752db 77 {
donatien 3:4394986752db 78 DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i);
donatien 3:4394986752db 79 m_pHost->bulkWrite(pDev, pEp, vodafone_k3770_switch_packet, 31);
donatien 3:4394986752db 80 return true;
donatien 3:4394986752db 81 }
donatien 3:4394986752db 82 }
donatien 3:4394986752db 83 }
donatien 3:4394986752db 84 return false;
donatien 3:4394986752db 85 }
donatien 3:4394986752db 86
donatien 9:c9e9817c398c 87 USBEndpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
donatien 3:4394986752db 88 {
donatien 6:075e36a3463e 89 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
donatien 3:4394986752db 90 }
donatien 3:4394986752db 91
donatien 3:4394986752db 92 int VodafoneK3770Initializer::getSerialPortCount()
donatien 3:4394986752db 93 {
donatien 6:075e36a3463e 94 return 2;
donatien 6:075e36a3463e 95 }
donatien 6:075e36a3463e 96
donatien 6:075e36a3463e 97 /*virtual*/ void VodafoneK3770Initializer::setVidPid(uint16_t vid, uint16_t pid)
donatien 6:075e36a3463e 98 {
donatien 6:075e36a3463e 99 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
donatien 6:075e36a3463e 100 {
donatien 6:075e36a3463e 101 m_hasSwitched = true;
donatien 6:075e36a3463e 102 m_currentSerialIntf = 0;
donatien 6:075e36a3463e 103 m_endpointsToFetch = 4;
donatien 6:075e36a3463e 104 }
donatien 6:075e36a3463e 105 else
donatien 6:075e36a3463e 106 {
donatien 6:075e36a3463e 107 m_hasSwitched = false;
donatien 6:075e36a3463e 108 m_endpointsToFetch = 1;
donatien 6:075e36a3463e 109 }
donatien 3:4394986752db 110 }
donatien 3:4394986752db 111
donatien 6:075e36a3463e 112 /*virtual*/ bool VodafoneK3770Initializer::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
donatien 6:075e36a3463e 113 {
donatien 6:075e36a3463e 114 if( m_hasSwitched )
donatien 6:075e36a3463e 115 {
donatien 6:075e36a3463e 116 if( intf_class == 0xFF )
donatien 6:075e36a3463e 117 {
donatien 6:075e36a3463e 118 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) )
donatien 6:075e36a3463e 119 {
donatien 6:075e36a3463e 120 m_currentSerialIntf++;
donatien 6:075e36a3463e 121 return true;
donatien 6:075e36a3463e 122 }
donatien 6:075e36a3463e 123 m_currentSerialIntf++;
donatien 6:075e36a3463e 124 }
donatien 6:075e36a3463e 125 }
donatien 6:075e36a3463e 126 else
donatien 6:075e36a3463e 127 {
donatien 6:075e36a3463e 128 if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
donatien 6:075e36a3463e 129 {
donatien 6:075e36a3463e 130 return true;
donatien 6:075e36a3463e 131 }
donatien 6:075e36a3463e 132 }
donatien 6:075e36a3463e 133 return false;
donatien 6:075e36a3463e 134 }
donatien 6:075e36a3463e 135
donatien 6:075e36a3463e 136 /*virtual*/ bool VodafoneK3770Initializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
donatien 6:075e36a3463e 137 {
donatien 6:075e36a3463e 138 if( m_hasSwitched )
donatien 6:075e36a3463e 139 {
donatien 6:075e36a3463e 140 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
donatien 6:075e36a3463e 141 {
donatien 6:075e36a3463e 142 m_endpointsToFetch--;
donatien 6:075e36a3463e 143 return true;
donatien 6:075e36a3463e 144 }
donatien 6:075e36a3463e 145 }
donatien 6:075e36a3463e 146 else
donatien 6:075e36a3463e 147 {
donatien 6:075e36a3463e 148 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
donatien 6:075e36a3463e 149 {
donatien 6:075e36a3463e 150 m_endpointsToFetch--;
donatien 6:075e36a3463e 151 return true;
donatien 6:075e36a3463e 152 }
donatien 6:075e36a3463e 153 }
donatien 6:075e36a3463e 154 return false;
donatien 6:075e36a3463e 155 }
donatien 8:0d1ec493842c 156
donatien 8:0d1ec493842c 157 /*virtual*/ WAN_DONGLE_TYPE VodafoneK3770Initializer::getType()
donatien 8:0d1ec493842c 158 {
donatien 8:0d1ec493842c 159 return WAN_DONGLE_TYPE_VODAFONEK3770;
donatien 8:0d1ec493842c 160 }
donatien 8:0d1ec493842c 161
ashleymills 21:dcc8c866ccbb 162 //Huawei MU509 (Module)
ashleymills 21:dcc8c866ccbb 163
ashleymills 21:dcc8c866ccbb 164 VodafoneMU509Initializer::VodafoneMU509Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
ashleymills 21:dcc8c866ccbb 165 {
ashleymills 21:dcc8c866ccbb 166
ashleymills 21:dcc8c866ccbb 167 }
ashleymills 21:dcc8c866ccbb 168
ashleymills 21:dcc8c866ccbb 169 uint16_t VodafoneMU509Initializer::getMSDVid() { return 0x12D1; }
donatien 22:bec61bcc9c25 170 uint16_t VodafoneMU509Initializer::getMSDPid() { return 0x0000; } //No MSD mode (presumably)
ashleymills 21:dcc8c866ccbb 171
ashleymills 21:dcc8c866ccbb 172 uint16_t VodafoneMU509Initializer::getSerialVid() { return 0x12D1; }
ashleymills 21:dcc8c866ccbb 173 uint16_t VodafoneMU509Initializer::getSerialPid() { return 0x1001; }
ashleymills 21:dcc8c866ccbb 174
ashleymills 21:dcc8c866ccbb 175 bool VodafoneMU509Initializer::switchMode(USBDeviceConnected* pDev)
ashleymills 21:dcc8c866ccbb 176 {
donatien 22:bec61bcc9c25 177 return true; //No MSD mode
ashleymills 21:dcc8c866ccbb 178 }
ashleymills 21:dcc8c866ccbb 179
ashleymills 21:dcc8c866ccbb 180 USBEndpoint* VodafoneMU509Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
ashleymills 21:dcc8c866ccbb 181 {
ashleymills 24:f4b676f61906 182 /*
ashleymills 24:f4b676f61906 183 int sPort = serialPortNumber;
ashleymills 24:f4b676f61906 184 if(sPort==1)
ashleymills 24:f4b676f61906 185 sPort = 0;
ashleymills 24:f4b676f61906 186 if(sPort==2)
ashleymills 24:f4b676f61906 187 sPort = 1;
ashleymills 24:f4b676f61906 188 if(sPort==0)
ashleymills 24:f4b676f61906 189 sPort = 2;
ashleymills 24:f4b676f61906 190 return pDev->getEndpoint(sPort, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 24:f4b676f61906 191 */
ashleymills 24:f4b676f61906 192 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 24:f4b676f61906 193 //return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 21:dcc8c866ccbb 194 }
ashleymills 21:dcc8c866ccbb 195
ashleymills 21:dcc8c866ccbb 196 int VodafoneMU509Initializer::getSerialPortCount()
ashleymills 21:dcc8c866ccbb 197 {
donatien 22:bec61bcc9c25 198 return 2;
ashleymills 21:dcc8c866ccbb 199 }
ashleymills 21:dcc8c866ccbb 200
ashleymills 21:dcc8c866ccbb 201 /*virtual*/ void VodafoneMU509Initializer::setVidPid(uint16_t vid, uint16_t pid)
ashleymills 21:dcc8c866ccbb 202 {
donatien 22:bec61bcc9c25 203 m_currentSerialIntf = 0;
donatien 22:bec61bcc9c25 204 m_endpointsToFetch = 4;
ashleymills 21:dcc8c866ccbb 205 }
ashleymills 21:dcc8c866ccbb 206
ashleymills 21:dcc8c866ccbb 207 /*virtual*/ bool VodafoneMU509Initializer::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
ashleymills 21:dcc8c866ccbb 208 {
donatien 22:bec61bcc9c25 209 if( intf_class == 0xFF )
ashleymills 21:dcc8c866ccbb 210 {
ashleymills 24:f4b676f61906 211 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 2) )
ashleymills 21:dcc8c866ccbb 212 {
ashleymills 21:dcc8c866ccbb 213 m_currentSerialIntf++;
ashleymills 21:dcc8c866ccbb 214 return true;
ashleymills 21:dcc8c866ccbb 215 }
donatien 22:bec61bcc9c25 216 m_currentSerialIntf++;
ashleymills 21:dcc8c866ccbb 217 }
ashleymills 21:dcc8c866ccbb 218 return false;
ashleymills 21:dcc8c866ccbb 219 }
ashleymills 21:dcc8c866ccbb 220
ashleymills 21:dcc8c866ccbb 221 /*virtual*/ bool VodafoneMU509Initializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
ashleymills 21:dcc8c866ccbb 222 {
donatien 22:bec61bcc9c25 223 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
ashleymills 21:dcc8c866ccbb 224 {
ashleymills 24:f4b676f61906 225 DBG("new endpoint");
donatien 22:bec61bcc9c25 226 m_endpointsToFetch--;
donatien 22:bec61bcc9c25 227 return true;
ashleymills 21:dcc8c866ccbb 228 }
ashleymills 21:dcc8c866ccbb 229 return false;
ashleymills 21:dcc8c866ccbb 230 }
ashleymills 21:dcc8c866ccbb 231
ashleymills 21:dcc8c866ccbb 232 /*virtual*/ WAN_DONGLE_TYPE VodafoneMU509Initializer::getType()
ashleymills 21:dcc8c866ccbb 233 {
ashleymills 21:dcc8c866ccbb 234 return WAN_DONGLE_TYPE_VODAFONEMU509;
ashleymills 21:dcc8c866ccbb 235 }
ashleymills 21:dcc8c866ccbb 236
ashleymills 20:3abcf818be31 237 //Huawei K3773 (Vodafone)
ashleymills 20:3abcf818be31 238 // Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 00 11 06 20 00 00 01 00 00 00 00 00 00 00 00 00 00"
ashleymills 20:3abcf818be31 239 static uint8_t vodafone_k3773_switch_packet[] = {
ashleymills 20:3abcf818be31 240 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x06, 0x20, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
ashleymills 20:3abcf818be31 241 };
ashleymills 20:3abcf818be31 242
ashleymills 20:3abcf818be31 243 VodafoneK3773Initializer::VodafoneK3773Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
ashleymills 20:3abcf818be31 244 {
ashleymills 20:3abcf818be31 245
ashleymills 20:3abcf818be31 246 }
ashleymills 20:3abcf818be31 247
ashleymills 20:3abcf818be31 248 uint16_t VodafoneK3773Initializer::getMSDVid() { return 0x12D1; }
ashleymills 20:3abcf818be31 249 uint16_t VodafoneK3773Initializer::getMSDPid() { return 0x1506; }
ashleymills 20:3abcf818be31 250
ashleymills 20:3abcf818be31 251 uint16_t VodafoneK3773Initializer::getSerialVid() { return 0x12D1; }
ashleymills 20:3abcf818be31 252 uint16_t VodafoneK3773Initializer::getSerialPid() { return 0x1506; }
ashleymills 20:3abcf818be31 253
ashleymills 20:3abcf818be31 254 bool VodafoneK3773Initializer::switchMode(USBDeviceConnected* pDev)
ashleymills 20:3abcf818be31 255 {
ashleymills 20:3abcf818be31 256 for (int i = 0; i < pDev->getNbInterface(); i++)
ashleymills 20:3abcf818be31 257 {
ashleymills 20:3abcf818be31 258 if (pDev->getInterface(i)->intf_class == MSD_CLASS)
ashleymills 20:3abcf818be31 259 {
ashleymills 20:3abcf818be31 260 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
ashleymills 20:3abcf818be31 261 if ( pEp != NULL )
ashleymills 20:3abcf818be31 262 {
ashleymills 20:3abcf818be31 263 DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i);
ashleymills 20:3abcf818be31 264 m_pHost->bulkWrite(pDev, pEp, vodafone_k3773_switch_packet, 31);
ashleymills 20:3abcf818be31 265 return true;
ashleymills 20:3abcf818be31 266 }
ashleymills 20:3abcf818be31 267 }
ashleymills 20:3abcf818be31 268 }
ashleymills 20:3abcf818be31 269 return false;
ashleymills 20:3abcf818be31 270 }
ashleymills 20:3abcf818be31 271
ashleymills 20:3abcf818be31 272 USBEndpoint* VodafoneK3773Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
ashleymills 20:3abcf818be31 273 {
ashleymills 20:3abcf818be31 274 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 20:3abcf818be31 275 }
ashleymills 20:3abcf818be31 276
ashleymills 20:3abcf818be31 277 int VodafoneK3773Initializer::getSerialPortCount()
ashleymills 20:3abcf818be31 278 {
ashleymills 20:3abcf818be31 279 return 2;
ashleymills 20:3abcf818be31 280 }
ashleymills 20:3abcf818be31 281
ashleymills 20:3abcf818be31 282 /*virtual*/ void VodafoneK3773Initializer::setVidPid(uint16_t vid, uint16_t pid)
ashleymills 20:3abcf818be31 283 {
ashleymills 20:3abcf818be31 284 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
ashleymills 20:3abcf818be31 285 {
ashleymills 20:3abcf818be31 286 m_hasSwitched = true;
ashleymills 20:3abcf818be31 287 m_currentSerialIntf = 0;
ashleymills 20:3abcf818be31 288 m_endpointsToFetch = 4;
ashleymills 20:3abcf818be31 289 }
ashleymills 20:3abcf818be31 290 else
ashleymills 20:3abcf818be31 291 {
ashleymills 20:3abcf818be31 292 m_hasSwitched = false;
ashleymills 20:3abcf818be31 293 m_endpointsToFetch = 1;
ashleymills 20:3abcf818be31 294 }
ashleymills 20:3abcf818be31 295 }
ashleymills 20:3abcf818be31 296
ashleymills 20:3abcf818be31 297 /*virtual*/ bool VodafoneK3773Initializer::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
ashleymills 20:3abcf818be31 298 {
ashleymills 20:3abcf818be31 299 if( m_hasSwitched )
ashleymills 20:3abcf818be31 300 {
ashleymills 20:3abcf818be31 301 if( intf_class == 0xFF )
ashleymills 20:3abcf818be31 302 {
ashleymills 20:3abcf818be31 303 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) )
ashleymills 20:3abcf818be31 304 {
ashleymills 20:3abcf818be31 305 m_currentSerialIntf++;
ashleymills 20:3abcf818be31 306 return true;
ashleymills 20:3abcf818be31 307 }
ashleymills 20:3abcf818be31 308 m_currentSerialIntf++;
ashleymills 20:3abcf818be31 309 }
ashleymills 20:3abcf818be31 310 }
ashleymills 20:3abcf818be31 311 else
ashleymills 20:3abcf818be31 312 {
ashleymills 20:3abcf818be31 313 if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
ashleymills 20:3abcf818be31 314 {
ashleymills 20:3abcf818be31 315 return true;
ashleymills 20:3abcf818be31 316 }
ashleymills 20:3abcf818be31 317 }
ashleymills 20:3abcf818be31 318 return false;
ashleymills 20:3abcf818be31 319 }
ashleymills 20:3abcf818be31 320
ashleymills 20:3abcf818be31 321 /*virtual*/ bool VodafoneK3773Initializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
ashleymills 20:3abcf818be31 322 {
ashleymills 20:3abcf818be31 323 if( m_hasSwitched )
ashleymills 20:3abcf818be31 324 {
ashleymills 20:3abcf818be31 325 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
ashleymills 20:3abcf818be31 326 {
ashleymills 20:3abcf818be31 327 m_endpointsToFetch--;
ashleymills 20:3abcf818be31 328 return true;
ashleymills 20:3abcf818be31 329 }
ashleymills 20:3abcf818be31 330 }
ashleymills 20:3abcf818be31 331 else
ashleymills 20:3abcf818be31 332 {
ashleymills 20:3abcf818be31 333 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
ashleymills 20:3abcf818be31 334 {
ashleymills 20:3abcf818be31 335 m_endpointsToFetch--;
ashleymills 20:3abcf818be31 336 return true;
ashleymills 20:3abcf818be31 337 }
ashleymills 20:3abcf818be31 338 }
ashleymills 20:3abcf818be31 339 return false;
ashleymills 20:3abcf818be31 340 }
ashleymills 20:3abcf818be31 341
ashleymills 20:3abcf818be31 342 /*virtual*/ WAN_DONGLE_TYPE VodafoneK3773Initializer::getType()
ashleymills 20:3abcf818be31 343 {
ashleymills 20:3abcf818be31 344 return WAN_DONGLE_TYPE_VODAFONEK3773;
ashleymills 20:3abcf818be31 345 }
ashleymills 20:3abcf818be31 346
donatien 8:0d1ec493842c 347 // NVIDIA (ICERA) /ZTE K3772-Z (Vodafone)
donatien 8:0d1ec493842c 348 // Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 06 1b 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00"
donatien 8:0d1ec493842c 349 static uint8_t vodafone_k3772_z_switch_packet[] = {
donatien 8:0d1ec493842c 350 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0x06, 0x1b, 0, 0, 0, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
donatien 8:0d1ec493842c 351 };
donatien 8:0d1ec493842c 352
donatien 8:0d1ec493842c 353 VodafoneK3772ZInitializer::VodafoneK3772ZInitializer(USBHost* pHost) : WANDongleInitializer(pHost)
donatien 8:0d1ec493842c 354 {
donatien 8:0d1ec493842c 355
donatien 8:0d1ec493842c 356 }
donatien 8:0d1ec493842c 357
donatien 8:0d1ec493842c 358 uint16_t VodafoneK3772ZInitializer::getMSDVid() { return 0x19D2; }
donatien 8:0d1ec493842c 359 uint16_t VodafoneK3772ZInitializer::getMSDPid() { return 0x1179; }
donatien 8:0d1ec493842c 360
donatien 8:0d1ec493842c 361 uint16_t VodafoneK3772ZInitializer::getSerialVid() { return 0x19D2; }
donatien 8:0d1ec493842c 362 uint16_t VodafoneK3772ZInitializer::getSerialPid() { return 0x1181; }
donatien 8:0d1ec493842c 363
donatien 8:0d1ec493842c 364 bool VodafoneK3772ZInitializer::switchMode(USBDeviceConnected* pDev)
donatien 8:0d1ec493842c 365 {
donatien 8:0d1ec493842c 366 for (int i = 0; i < pDev->getNbInterface(); i++)
donatien 8:0d1ec493842c 367 {
donatien 8:0d1ec493842c 368 if (pDev->getInterface(i)->intf_class == MSD_CLASS)
donatien 8:0d1ec493842c 369 {
donatien 9:c9e9817c398c 370 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
donatien 8:0d1ec493842c 371 if ( pEp != NULL )
donatien 8:0d1ec493842c 372 {
donatien 8:0d1ec493842c 373 DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i);
donatien 8:0d1ec493842c 374 m_pHost->bulkWrite(pDev, pEp, vodafone_k3772_z_switch_packet, 31);
donatien 8:0d1ec493842c 375 return true;
donatien 8:0d1ec493842c 376 }
donatien 8:0d1ec493842c 377 }
donatien 8:0d1ec493842c 378 }
donatien 8:0d1ec493842c 379 return false;
donatien 8:0d1ec493842c 380 }
donatien 8:0d1ec493842c 381
donatien 9:c9e9817c398c 382 USBEndpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
donatien 8:0d1ec493842c 383 {
donatien 8:0d1ec493842c 384 return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0);
donatien 8:0d1ec493842c 385 }
donatien 8:0d1ec493842c 386
donatien 8:0d1ec493842c 387 int VodafoneK3772ZInitializer::getSerialPortCount()
donatien 8:0d1ec493842c 388 {
donatien 8:0d1ec493842c 389 return 2;
donatien 8:0d1ec493842c 390 }
donatien 8:0d1ec493842c 391
donatien 8:0d1ec493842c 392 /*virtual*/ void VodafoneK3772ZInitializer::setVidPid(uint16_t vid, uint16_t pid)
donatien 8:0d1ec493842c 393 {
donatien 8:0d1ec493842c 394 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
donatien 8:0d1ec493842c 395 {
donatien 8:0d1ec493842c 396 m_hasSwitched = true;
donatien 8:0d1ec493842c 397 m_currentSerialIntf = 0;
donatien 8:0d1ec493842c 398 m_endpointsToFetch = 4;
donatien 8:0d1ec493842c 399 }
donatien 8:0d1ec493842c 400 else
donatien 8:0d1ec493842c 401 {
donatien 8:0d1ec493842c 402 m_hasSwitched = false;
donatien 8:0d1ec493842c 403 m_endpointsToFetch = 1;
donatien 8:0d1ec493842c 404 }
donatien 8:0d1ec493842c 405 }
donatien 8:0d1ec493842c 406
donatien 8:0d1ec493842c 407 /*virtual*/ bool VodafoneK3772ZInitializer::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
donatien 8:0d1ec493842c 408 {
donatien 8:0d1ec493842c 409 if( m_hasSwitched )
donatien 8:0d1ec493842c 410 {
donatien 8:0d1ec493842c 411 DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol);
donatien 8:0d1ec493842c 412 if( intf_class == 0x0A )
donatien 8:0d1ec493842c 413 {
donatien 8:0d1ec493842c 414 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) )
donatien 8:0d1ec493842c 415 {
donatien 8:0d1ec493842c 416 m_currentSerialIntf++;
donatien 8:0d1ec493842c 417 return true;
donatien 8:0d1ec493842c 418 }
donatien 8:0d1ec493842c 419 m_currentSerialIntf++;
donatien 8:0d1ec493842c 420 }
donatien 8:0d1ec493842c 421 }
donatien 8:0d1ec493842c 422 else
donatien 8:0d1ec493842c 423 {
donatien 8:0d1ec493842c 424 if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
donatien 8:0d1ec493842c 425 {
donatien 8:0d1ec493842c 426 return true;
donatien 8:0d1ec493842c 427 }
donatien 8:0d1ec493842c 428 }
donatien 8:0d1ec493842c 429 return false;
donatien 8:0d1ec493842c 430 }
donatien 8:0d1ec493842c 431
donatien 8:0d1ec493842c 432 /*virtual*/ bool VodafoneK3772ZInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
donatien 8:0d1ec493842c 433 {
donatien 8:0d1ec493842c 434 if( m_hasSwitched )
donatien 8:0d1ec493842c 435 {
donatien 9:c9e9817c398c 436 DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir);
donatien 8:0d1ec493842c 437 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
donatien 8:0d1ec493842c 438 {
donatien 8:0d1ec493842c 439 m_endpointsToFetch--;
donatien 8:0d1ec493842c 440 return true;
donatien 8:0d1ec493842c 441 }
donatien 8:0d1ec493842c 442 }
donatien 8:0d1ec493842c 443 else
donatien 8:0d1ec493842c 444 {
donatien 8:0d1ec493842c 445 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
donatien 8:0d1ec493842c 446 {
donatien 8:0d1ec493842c 447 m_endpointsToFetch--;
donatien 8:0d1ec493842c 448 return true;
donatien 8:0d1ec493842c 449 }
donatien 8:0d1ec493842c 450 }
donatien 8:0d1ec493842c 451 return false;
donatien 8:0d1ec493842c 452 }
donatien 8:0d1ec493842c 453
donatien 8:0d1ec493842c 454
donatien 8:0d1ec493842c 455 /*virtual*/ WAN_DONGLE_TYPE VodafoneK3772ZInitializer::getType()
donatien 8:0d1ec493842c 456 {
donatien 8:0d1ec493842c 457 return WAN_DONGLE_TYPE_VODAFONEK3772Z;
donatien 8:0d1ec493842c 458 }