local fork (temporary)

Dependents:   VodafoneUSBModem_bleedingedge2

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Committer:
donatien
Date:
Tue Dec 18 15:31:57 2012 +0000
Revision:
22:bec61bcc9c25
Parent:
21:dcc8c866ccbb
Child:
23:8f2d9a244224
Fetching endpoints on USB interfaces 0 & 1

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 20:3abcf818be31 19 #define __DEBUG__ 4
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 21:dcc8c866ccbb 182 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 21:dcc8c866ccbb 183 }
ashleymills 21:dcc8c866ccbb 184
ashleymills 21:dcc8c866ccbb 185 int VodafoneMU509Initializer::getSerialPortCount()
ashleymills 21:dcc8c866ccbb 186 {
donatien 22:bec61bcc9c25 187 return 2;
ashleymills 21:dcc8c866ccbb 188 }
ashleymills 21:dcc8c866ccbb 189
ashleymills 21:dcc8c866ccbb 190 /*virtual*/ void VodafoneMU509Initializer::setVidPid(uint16_t vid, uint16_t pid)
ashleymills 21:dcc8c866ccbb 191 {
donatien 22:bec61bcc9c25 192 m_currentSerialIntf = 0;
donatien 22:bec61bcc9c25 193 m_endpointsToFetch = 4;
ashleymills 21:dcc8c866ccbb 194 }
ashleymills 21:dcc8c866ccbb 195
ashleymills 21:dcc8c866ccbb 196 /*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 197 {
donatien 22:bec61bcc9c25 198 if( intf_class == 0xFF )
ashleymills 21:dcc8c866ccbb 199 {
donatien 22:bec61bcc9c25 200 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) )
ashleymills 21:dcc8c866ccbb 201 {
ashleymills 21:dcc8c866ccbb 202 m_currentSerialIntf++;
ashleymills 21:dcc8c866ccbb 203 return true;
ashleymills 21:dcc8c866ccbb 204 }
donatien 22:bec61bcc9c25 205 m_currentSerialIntf++;
ashleymills 21:dcc8c866ccbb 206 }
ashleymills 21:dcc8c866ccbb 207 return false;
ashleymills 21:dcc8c866ccbb 208 }
ashleymills 21:dcc8c866ccbb 209
ashleymills 21:dcc8c866ccbb 210 /*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 211 {
donatien 22:bec61bcc9c25 212 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
ashleymills 21:dcc8c866ccbb 213 {
donatien 22:bec61bcc9c25 214 m_endpointsToFetch--;
donatien 22:bec61bcc9c25 215 return true;
ashleymills 21:dcc8c866ccbb 216 }
ashleymills 21:dcc8c866ccbb 217 return false;
ashleymills 21:dcc8c866ccbb 218 }
ashleymills 21:dcc8c866ccbb 219
ashleymills 21:dcc8c866ccbb 220 /*virtual*/ WAN_DONGLE_TYPE VodafoneMU509Initializer::getType()
ashleymills 21:dcc8c866ccbb 221 {
ashleymills 21:dcc8c866ccbb 222 return WAN_DONGLE_TYPE_VODAFONEMU509;
ashleymills 21:dcc8c866ccbb 223 }
ashleymills 21:dcc8c866ccbb 224
ashleymills 20:3abcf818be31 225 //Huawei K3773 (Vodafone)
ashleymills 20:3abcf818be31 226 // 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 227 static uint8_t vodafone_k3773_switch_packet[] = {
ashleymills 20:3abcf818be31 228 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 229 };
ashleymills 20:3abcf818be31 230
ashleymills 20:3abcf818be31 231 VodafoneK3773Initializer::VodafoneK3773Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
ashleymills 20:3abcf818be31 232 {
ashleymills 20:3abcf818be31 233
ashleymills 20:3abcf818be31 234 }
ashleymills 20:3abcf818be31 235
ashleymills 20:3abcf818be31 236 uint16_t VodafoneK3773Initializer::getMSDVid() { return 0x12D1; }
ashleymills 20:3abcf818be31 237 uint16_t VodafoneK3773Initializer::getMSDPid() { return 0x1506; }
ashleymills 20:3abcf818be31 238
ashleymills 20:3abcf818be31 239 uint16_t VodafoneK3773Initializer::getSerialVid() { return 0x12D1; }
ashleymills 20:3abcf818be31 240 uint16_t VodafoneK3773Initializer::getSerialPid() { return 0x1506; }
ashleymills 20:3abcf818be31 241
ashleymills 20:3abcf818be31 242 bool VodafoneK3773Initializer::switchMode(USBDeviceConnected* pDev)
ashleymills 20:3abcf818be31 243 {
ashleymills 20:3abcf818be31 244 for (int i = 0; i < pDev->getNbInterface(); i++)
ashleymills 20:3abcf818be31 245 {
ashleymills 20:3abcf818be31 246 if (pDev->getInterface(i)->intf_class == MSD_CLASS)
ashleymills 20:3abcf818be31 247 {
ashleymills 20:3abcf818be31 248 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
ashleymills 20:3abcf818be31 249 if ( pEp != NULL )
ashleymills 20:3abcf818be31 250 {
ashleymills 20:3abcf818be31 251 DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i);
ashleymills 20:3abcf818be31 252 m_pHost->bulkWrite(pDev, pEp, vodafone_k3773_switch_packet, 31);
ashleymills 20:3abcf818be31 253 return true;
ashleymills 20:3abcf818be31 254 }
ashleymills 20:3abcf818be31 255 }
ashleymills 20:3abcf818be31 256 }
ashleymills 20:3abcf818be31 257 return false;
ashleymills 20:3abcf818be31 258 }
ashleymills 20:3abcf818be31 259
ashleymills 20:3abcf818be31 260 USBEndpoint* VodafoneK3773Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
ashleymills 20:3abcf818be31 261 {
ashleymills 20:3abcf818be31 262 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
ashleymills 20:3abcf818be31 263 }
ashleymills 20:3abcf818be31 264
ashleymills 20:3abcf818be31 265 int VodafoneK3773Initializer::getSerialPortCount()
ashleymills 20:3abcf818be31 266 {
ashleymills 20:3abcf818be31 267 return 2;
ashleymills 20:3abcf818be31 268 }
ashleymills 20:3abcf818be31 269
ashleymills 20:3abcf818be31 270 /*virtual*/ void VodafoneK3773Initializer::setVidPid(uint16_t vid, uint16_t pid)
ashleymills 20:3abcf818be31 271 {
ashleymills 20:3abcf818be31 272 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
ashleymills 20:3abcf818be31 273 {
ashleymills 20:3abcf818be31 274 m_hasSwitched = true;
ashleymills 20:3abcf818be31 275 m_currentSerialIntf = 0;
ashleymills 20:3abcf818be31 276 m_endpointsToFetch = 4;
ashleymills 20:3abcf818be31 277 }
ashleymills 20:3abcf818be31 278 else
ashleymills 20:3abcf818be31 279 {
ashleymills 20:3abcf818be31 280 m_hasSwitched = false;
ashleymills 20:3abcf818be31 281 m_endpointsToFetch = 1;
ashleymills 20:3abcf818be31 282 }
ashleymills 20:3abcf818be31 283 }
ashleymills 20:3abcf818be31 284
ashleymills 20:3abcf818be31 285 /*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 286 {
ashleymills 20:3abcf818be31 287 if( m_hasSwitched )
ashleymills 20:3abcf818be31 288 {
ashleymills 20:3abcf818be31 289 if( intf_class == 0xFF )
ashleymills 20:3abcf818be31 290 {
ashleymills 20:3abcf818be31 291 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) )
ashleymills 20:3abcf818be31 292 {
ashleymills 20:3abcf818be31 293 m_currentSerialIntf++;
ashleymills 20:3abcf818be31 294 return true;
ashleymills 20:3abcf818be31 295 }
ashleymills 20:3abcf818be31 296 m_currentSerialIntf++;
ashleymills 20:3abcf818be31 297 }
ashleymills 20:3abcf818be31 298 }
ashleymills 20:3abcf818be31 299 else
ashleymills 20:3abcf818be31 300 {
ashleymills 20:3abcf818be31 301 if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
ashleymills 20:3abcf818be31 302 {
ashleymills 20:3abcf818be31 303 return true;
ashleymills 20:3abcf818be31 304 }
ashleymills 20:3abcf818be31 305 }
ashleymills 20:3abcf818be31 306 return false;
ashleymills 20:3abcf818be31 307 }
ashleymills 20:3abcf818be31 308
ashleymills 20:3abcf818be31 309 /*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 310 {
ashleymills 20:3abcf818be31 311 if( m_hasSwitched )
ashleymills 20:3abcf818be31 312 {
ashleymills 20:3abcf818be31 313 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
ashleymills 20:3abcf818be31 314 {
ashleymills 20:3abcf818be31 315 m_endpointsToFetch--;
ashleymills 20:3abcf818be31 316 return true;
ashleymills 20:3abcf818be31 317 }
ashleymills 20:3abcf818be31 318 }
ashleymills 20:3abcf818be31 319 else
ashleymills 20:3abcf818be31 320 {
ashleymills 20:3abcf818be31 321 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
ashleymills 20:3abcf818be31 322 {
ashleymills 20:3abcf818be31 323 m_endpointsToFetch--;
ashleymills 20:3abcf818be31 324 return true;
ashleymills 20:3abcf818be31 325 }
ashleymills 20:3abcf818be31 326 }
ashleymills 20:3abcf818be31 327 return false;
ashleymills 20:3abcf818be31 328 }
ashleymills 20:3abcf818be31 329
ashleymills 20:3abcf818be31 330 /*virtual*/ WAN_DONGLE_TYPE VodafoneK3773Initializer::getType()
ashleymills 20:3abcf818be31 331 {
ashleymills 20:3abcf818be31 332 return WAN_DONGLE_TYPE_VODAFONEK3773;
ashleymills 20:3abcf818be31 333 }
ashleymills 20:3abcf818be31 334
donatien 8:0d1ec493842c 335 // NVIDIA (ICERA) /ZTE K3772-Z (Vodafone)
donatien 8:0d1ec493842c 336 // 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 337 static uint8_t vodafone_k3772_z_switch_packet[] = {
donatien 8:0d1ec493842c 338 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 339 };
donatien 8:0d1ec493842c 340
donatien 8:0d1ec493842c 341 VodafoneK3772ZInitializer::VodafoneK3772ZInitializer(USBHost* pHost) : WANDongleInitializer(pHost)
donatien 8:0d1ec493842c 342 {
donatien 8:0d1ec493842c 343
donatien 8:0d1ec493842c 344 }
donatien 8:0d1ec493842c 345
donatien 8:0d1ec493842c 346 uint16_t VodafoneK3772ZInitializer::getMSDVid() { return 0x19D2; }
donatien 8:0d1ec493842c 347 uint16_t VodafoneK3772ZInitializer::getMSDPid() { return 0x1179; }
donatien 8:0d1ec493842c 348
donatien 8:0d1ec493842c 349 uint16_t VodafoneK3772ZInitializer::getSerialVid() { return 0x19D2; }
donatien 8:0d1ec493842c 350 uint16_t VodafoneK3772ZInitializer::getSerialPid() { return 0x1181; }
donatien 8:0d1ec493842c 351
donatien 8:0d1ec493842c 352 bool VodafoneK3772ZInitializer::switchMode(USBDeviceConnected* pDev)
donatien 8:0d1ec493842c 353 {
donatien 8:0d1ec493842c 354 for (int i = 0; i < pDev->getNbInterface(); i++)
donatien 8:0d1ec493842c 355 {
donatien 8:0d1ec493842c 356 if (pDev->getInterface(i)->intf_class == MSD_CLASS)
donatien 8:0d1ec493842c 357 {
donatien 9:c9e9817c398c 358 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
donatien 8:0d1ec493842c 359 if ( pEp != NULL )
donatien 8:0d1ec493842c 360 {
donatien 8:0d1ec493842c 361 DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i);
donatien 8:0d1ec493842c 362 m_pHost->bulkWrite(pDev, pEp, vodafone_k3772_z_switch_packet, 31);
donatien 8:0d1ec493842c 363 return true;
donatien 8:0d1ec493842c 364 }
donatien 8:0d1ec493842c 365 }
donatien 8:0d1ec493842c 366 }
donatien 8:0d1ec493842c 367 return false;
donatien 8:0d1ec493842c 368 }
donatien 8:0d1ec493842c 369
donatien 9:c9e9817c398c 370 USBEndpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
donatien 8:0d1ec493842c 371 {
donatien 8:0d1ec493842c 372 return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0);
donatien 8:0d1ec493842c 373 }
donatien 8:0d1ec493842c 374
donatien 8:0d1ec493842c 375 int VodafoneK3772ZInitializer::getSerialPortCount()
donatien 8:0d1ec493842c 376 {
donatien 8:0d1ec493842c 377 return 2;
donatien 8:0d1ec493842c 378 }
donatien 8:0d1ec493842c 379
donatien 8:0d1ec493842c 380 /*virtual*/ void VodafoneK3772ZInitializer::setVidPid(uint16_t vid, uint16_t pid)
donatien 8:0d1ec493842c 381 {
donatien 8:0d1ec493842c 382 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
donatien 8:0d1ec493842c 383 {
donatien 8:0d1ec493842c 384 m_hasSwitched = true;
donatien 8:0d1ec493842c 385 m_currentSerialIntf = 0;
donatien 8:0d1ec493842c 386 m_endpointsToFetch = 4;
donatien 8:0d1ec493842c 387 }
donatien 8:0d1ec493842c 388 else
donatien 8:0d1ec493842c 389 {
donatien 8:0d1ec493842c 390 m_hasSwitched = false;
donatien 8:0d1ec493842c 391 m_endpointsToFetch = 1;
donatien 8:0d1ec493842c 392 }
donatien 8:0d1ec493842c 393 }
donatien 8:0d1ec493842c 394
donatien 8:0d1ec493842c 395 /*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 396 {
donatien 8:0d1ec493842c 397 if( m_hasSwitched )
donatien 8:0d1ec493842c 398 {
donatien 8:0d1ec493842c 399 DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol);
donatien 8:0d1ec493842c 400 if( intf_class == 0x0A )
donatien 8:0d1ec493842c 401 {
donatien 8:0d1ec493842c 402 if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) )
donatien 8:0d1ec493842c 403 {
donatien 8:0d1ec493842c 404 m_currentSerialIntf++;
donatien 8:0d1ec493842c 405 return true;
donatien 8:0d1ec493842c 406 }
donatien 8:0d1ec493842c 407 m_currentSerialIntf++;
donatien 8:0d1ec493842c 408 }
donatien 8:0d1ec493842c 409 }
donatien 8:0d1ec493842c 410 else
donatien 8:0d1ec493842c 411 {
donatien 8:0d1ec493842c 412 if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
donatien 8:0d1ec493842c 413 {
donatien 8:0d1ec493842c 414 return true;
donatien 8:0d1ec493842c 415 }
donatien 8:0d1ec493842c 416 }
donatien 8:0d1ec493842c 417 return false;
donatien 8:0d1ec493842c 418 }
donatien 8:0d1ec493842c 419
donatien 8:0d1ec493842c 420 /*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 421 {
donatien 8:0d1ec493842c 422 if( m_hasSwitched )
donatien 8:0d1ec493842c 423 {
donatien 9:c9e9817c398c 424 DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir);
donatien 8:0d1ec493842c 425 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
donatien 8:0d1ec493842c 426 {
donatien 8:0d1ec493842c 427 m_endpointsToFetch--;
donatien 8:0d1ec493842c 428 return true;
donatien 8:0d1ec493842c 429 }
donatien 8:0d1ec493842c 430 }
donatien 8:0d1ec493842c 431 else
donatien 8:0d1ec493842c 432 {
donatien 8:0d1ec493842c 433 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
donatien 8:0d1ec493842c 434 {
donatien 8:0d1ec493842c 435 m_endpointsToFetch--;
donatien 8:0d1ec493842c 436 return true;
donatien 8:0d1ec493842c 437 }
donatien 8:0d1ec493842c 438 }
donatien 8:0d1ec493842c 439 return false;
donatien 8:0d1ec493842c 440 }
donatien 8:0d1ec493842c 441
donatien 8:0d1ec493842c 442
donatien 8:0d1ec493842c 443 /*virtual*/ WAN_DONGLE_TYPE VodafoneK3772ZInitializer::getType()
donatien 8:0d1ec493842c 444 {
donatien 8:0d1ec493842c 445 return WAN_DONGLE_TYPE_VODAFONEK3772Z;
donatien 8:0d1ec493842c 446 }