USB Host WAN Dongle library
Fork of USBHostWANDongle_bleedingedge by
USB3GModule/WANDongleInitializer.cpp@20:3abcf818be31, 2012-12-13 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Dec 13 14:56:55 2012 +0000
- Revision:
- 20:3abcf818be31
- Parent:
- 13:c154e7f2e42f
- Child:
- 21:dcc8c866ccbb
Added stuff for K3773 support
Who changed what in which revision?
User | Revision | Line number | New 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 | 20:3abcf818be31 | 41 | const static WANDongleInitializer* list[] = { &vodafoneK3770, &vodafoneK3772Z, &vodafoneK3773, NULL }; |
donatien | 3:4394986752db | 42 | return (WANDongleInitializer**)list; |
donatien | 3:4394986752db | 43 | } |
donatien | 3:4394986752db | 44 | |
donatien | 3:4394986752db | 45 | //Huawei K3770 (Vodafone) |
nherriot | 5:3189db174f6b | 46 | // 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 | 47 | static uint8_t vodafone_k3770_switch_packet[] = { |
donatien | 3:4394986752db | 48 | 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 | 49 | }; |
donatien | 3:4394986752db | 50 | |
donatien | 3:4394986752db | 51 | VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost) |
donatien | 3:4394986752db | 52 | { |
donatien | 3:4394986752db | 53 | |
donatien | 3:4394986752db | 54 | } |
donatien | 3:4394986752db | 55 | |
donatien | 3:4394986752db | 56 | uint16_t VodafoneK3770Initializer::getMSDVid() { return 0x12D1; } |
donatien | 3:4394986752db | 57 | uint16_t VodafoneK3770Initializer::getMSDPid() { return 0x14D1; } |
donatien | 3:4394986752db | 58 | |
donatien | 3:4394986752db | 59 | uint16_t VodafoneK3770Initializer::getSerialVid() { return 0x12D1; } |
donatien | 3:4394986752db | 60 | uint16_t VodafoneK3770Initializer::getSerialPid() { return 0x14C9; } |
donatien | 3:4394986752db | 61 | |
donatien | 3:4394986752db | 62 | bool VodafoneK3770Initializer::switchMode(USBDeviceConnected* pDev) |
donatien | 3:4394986752db | 63 | { |
donatien | 3:4394986752db | 64 | for (int i = 0; i < pDev->getNbInterface(); i++) |
donatien | 3:4394986752db | 65 | { |
donatien | 3:4394986752db | 66 | if (pDev->getInterface(i)->intf_class == MSD_CLASS) |
donatien | 3:4394986752db | 67 | { |
donatien | 9:c9e9817c398c | 68 | USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); |
donatien | 3:4394986752db | 69 | if ( pEp != NULL ) |
donatien | 3:4394986752db | 70 | { |
donatien | 3:4394986752db | 71 | DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); |
donatien | 3:4394986752db | 72 | m_pHost->bulkWrite(pDev, pEp, vodafone_k3770_switch_packet, 31); |
donatien | 3:4394986752db | 73 | return true; |
donatien | 3:4394986752db | 74 | } |
donatien | 3:4394986752db | 75 | } |
donatien | 3:4394986752db | 76 | } |
donatien | 3:4394986752db | 77 | return false; |
donatien | 3:4394986752db | 78 | } |
donatien | 3:4394986752db | 79 | |
donatien | 9:c9e9817c398c | 80 | USBEndpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) |
donatien | 3:4394986752db | 81 | { |
donatien | 6:075e36a3463e | 82 | return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); |
donatien | 3:4394986752db | 83 | } |
donatien | 3:4394986752db | 84 | |
donatien | 3:4394986752db | 85 | int VodafoneK3770Initializer::getSerialPortCount() |
donatien | 3:4394986752db | 86 | { |
donatien | 6:075e36a3463e | 87 | return 2; |
donatien | 6:075e36a3463e | 88 | } |
donatien | 6:075e36a3463e | 89 | |
donatien | 6:075e36a3463e | 90 | /*virtual*/ void VodafoneK3770Initializer::setVidPid(uint16_t vid, uint16_t pid) |
donatien | 6:075e36a3463e | 91 | { |
donatien | 6:075e36a3463e | 92 | if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) |
donatien | 6:075e36a3463e | 93 | { |
donatien | 6:075e36a3463e | 94 | m_hasSwitched = true; |
donatien | 6:075e36a3463e | 95 | m_currentSerialIntf = 0; |
donatien | 6:075e36a3463e | 96 | m_endpointsToFetch = 4; |
donatien | 6:075e36a3463e | 97 | } |
donatien | 6:075e36a3463e | 98 | else |
donatien | 6:075e36a3463e | 99 | { |
donatien | 6:075e36a3463e | 100 | m_hasSwitched = false; |
donatien | 6:075e36a3463e | 101 | m_endpointsToFetch = 1; |
donatien | 6:075e36a3463e | 102 | } |
donatien | 3:4394986752db | 103 | } |
donatien | 3:4394986752db | 104 | |
donatien | 6:075e36a3463e | 105 | /*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 | 106 | { |
donatien | 6:075e36a3463e | 107 | if( m_hasSwitched ) |
donatien | 6:075e36a3463e | 108 | { |
donatien | 6:075e36a3463e | 109 | if( intf_class == 0xFF ) |
donatien | 6:075e36a3463e | 110 | { |
donatien | 6:075e36a3463e | 111 | if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) ) |
donatien | 6:075e36a3463e | 112 | { |
donatien | 6:075e36a3463e | 113 | m_currentSerialIntf++; |
donatien | 6:075e36a3463e | 114 | return true; |
donatien | 6:075e36a3463e | 115 | } |
donatien | 6:075e36a3463e | 116 | m_currentSerialIntf++; |
donatien | 6:075e36a3463e | 117 | } |
donatien | 6:075e36a3463e | 118 | } |
donatien | 6:075e36a3463e | 119 | else |
donatien | 6:075e36a3463e | 120 | { |
donatien | 6:075e36a3463e | 121 | if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) |
donatien | 6:075e36a3463e | 122 | { |
donatien | 6:075e36a3463e | 123 | return true; |
donatien | 6:075e36a3463e | 124 | } |
donatien | 6:075e36a3463e | 125 | } |
donatien | 6:075e36a3463e | 126 | return false; |
donatien | 6:075e36a3463e | 127 | } |
donatien | 6:075e36a3463e | 128 | |
donatien | 6:075e36a3463e | 129 | /*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 | 130 | { |
donatien | 6:075e36a3463e | 131 | if( m_hasSwitched ) |
donatien | 6:075e36a3463e | 132 | { |
donatien | 6:075e36a3463e | 133 | if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) |
donatien | 6:075e36a3463e | 134 | { |
donatien | 6:075e36a3463e | 135 | m_endpointsToFetch--; |
donatien | 6:075e36a3463e | 136 | return true; |
donatien | 6:075e36a3463e | 137 | } |
donatien | 6:075e36a3463e | 138 | } |
donatien | 6:075e36a3463e | 139 | else |
donatien | 6:075e36a3463e | 140 | { |
donatien | 6:075e36a3463e | 141 | if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) |
donatien | 6:075e36a3463e | 142 | { |
donatien | 6:075e36a3463e | 143 | m_endpointsToFetch--; |
donatien | 6:075e36a3463e | 144 | return true; |
donatien | 6:075e36a3463e | 145 | } |
donatien | 6:075e36a3463e | 146 | } |
donatien | 6:075e36a3463e | 147 | return false; |
donatien | 6:075e36a3463e | 148 | } |
donatien | 8:0d1ec493842c | 149 | |
donatien | 8:0d1ec493842c | 150 | /*virtual*/ WAN_DONGLE_TYPE VodafoneK3770Initializer::getType() |
donatien | 8:0d1ec493842c | 151 | { |
donatien | 8:0d1ec493842c | 152 | return WAN_DONGLE_TYPE_VODAFONEK3770; |
donatien | 8:0d1ec493842c | 153 | } |
donatien | 8:0d1ec493842c | 154 | |
ashleymills | 20:3abcf818be31 | 155 | //Huawei K3773 (Vodafone) |
ashleymills | 20:3abcf818be31 | 156 | // 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 | 157 | static uint8_t vodafone_k3773_switch_packet[] = { |
ashleymills | 20:3abcf818be31 | 158 | 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 | 159 | }; |
ashleymills | 20:3abcf818be31 | 160 | |
ashleymills | 20:3abcf818be31 | 161 | VodafoneK3773Initializer::VodafoneK3773Initializer(USBHost* pHost) : WANDongleInitializer(pHost) |
ashleymills | 20:3abcf818be31 | 162 | { |
ashleymills | 20:3abcf818be31 | 163 | |
ashleymills | 20:3abcf818be31 | 164 | } |
ashleymills | 20:3abcf818be31 | 165 | |
ashleymills | 20:3abcf818be31 | 166 | uint16_t VodafoneK3773Initializer::getMSDVid() { return 0x12D1; } |
ashleymills | 20:3abcf818be31 | 167 | uint16_t VodafoneK3773Initializer::getMSDPid() { return 0x1506; } |
ashleymills | 20:3abcf818be31 | 168 | |
ashleymills | 20:3abcf818be31 | 169 | uint16_t VodafoneK3773Initializer::getSerialVid() { return 0x12D1; } |
ashleymills | 20:3abcf818be31 | 170 | uint16_t VodafoneK3773Initializer::getSerialPid() { return 0x1506; } |
ashleymills | 20:3abcf818be31 | 171 | |
ashleymills | 20:3abcf818be31 | 172 | bool VodafoneK3773Initializer::switchMode(USBDeviceConnected* pDev) |
ashleymills | 20:3abcf818be31 | 173 | { |
ashleymills | 20:3abcf818be31 | 174 | for (int i = 0; i < pDev->getNbInterface(); i++) |
ashleymills | 20:3abcf818be31 | 175 | { |
ashleymills | 20:3abcf818be31 | 176 | if (pDev->getInterface(i)->intf_class == MSD_CLASS) |
ashleymills | 20:3abcf818be31 | 177 | { |
ashleymills | 20:3abcf818be31 | 178 | USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); |
ashleymills | 20:3abcf818be31 | 179 | if ( pEp != NULL ) |
ashleymills | 20:3abcf818be31 | 180 | { |
ashleymills | 20:3abcf818be31 | 181 | DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); |
ashleymills | 20:3abcf818be31 | 182 | m_pHost->bulkWrite(pDev, pEp, vodafone_k3773_switch_packet, 31); |
ashleymills | 20:3abcf818be31 | 183 | return true; |
ashleymills | 20:3abcf818be31 | 184 | } |
ashleymills | 20:3abcf818be31 | 185 | } |
ashleymills | 20:3abcf818be31 | 186 | } |
ashleymills | 20:3abcf818be31 | 187 | return false; |
ashleymills | 20:3abcf818be31 | 188 | } |
ashleymills | 20:3abcf818be31 | 189 | |
ashleymills | 20:3abcf818be31 | 190 | USBEndpoint* VodafoneK3773Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) |
ashleymills | 20:3abcf818be31 | 191 | { |
ashleymills | 20:3abcf818be31 | 192 | return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); |
ashleymills | 20:3abcf818be31 | 193 | } |
ashleymills | 20:3abcf818be31 | 194 | |
ashleymills | 20:3abcf818be31 | 195 | int VodafoneK3773Initializer::getSerialPortCount() |
ashleymills | 20:3abcf818be31 | 196 | { |
ashleymills | 20:3abcf818be31 | 197 | return 2; |
ashleymills | 20:3abcf818be31 | 198 | } |
ashleymills | 20:3abcf818be31 | 199 | |
ashleymills | 20:3abcf818be31 | 200 | /*virtual*/ void VodafoneK3773Initializer::setVidPid(uint16_t vid, uint16_t pid) |
ashleymills | 20:3abcf818be31 | 201 | { |
ashleymills | 20:3abcf818be31 | 202 | if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) |
ashleymills | 20:3abcf818be31 | 203 | { |
ashleymills | 20:3abcf818be31 | 204 | m_hasSwitched = true; |
ashleymills | 20:3abcf818be31 | 205 | m_currentSerialIntf = 0; |
ashleymills | 20:3abcf818be31 | 206 | m_endpointsToFetch = 4; |
ashleymills | 20:3abcf818be31 | 207 | } |
ashleymills | 20:3abcf818be31 | 208 | else |
ashleymills | 20:3abcf818be31 | 209 | { |
ashleymills | 20:3abcf818be31 | 210 | m_hasSwitched = false; |
ashleymills | 20:3abcf818be31 | 211 | m_endpointsToFetch = 1; |
ashleymills | 20:3abcf818be31 | 212 | } |
ashleymills | 20:3abcf818be31 | 213 | } |
ashleymills | 20:3abcf818be31 | 214 | |
ashleymills | 20:3abcf818be31 | 215 | /*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 | 216 | { |
ashleymills | 20:3abcf818be31 | 217 | if( m_hasSwitched ) |
ashleymills | 20:3abcf818be31 | 218 | { |
ashleymills | 20:3abcf818be31 | 219 | if( intf_class == 0xFF ) |
ashleymills | 20:3abcf818be31 | 220 | { |
ashleymills | 20:3abcf818be31 | 221 | if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) ) |
ashleymills | 20:3abcf818be31 | 222 | { |
ashleymills | 20:3abcf818be31 | 223 | m_currentSerialIntf++; |
ashleymills | 20:3abcf818be31 | 224 | return true; |
ashleymills | 20:3abcf818be31 | 225 | } |
ashleymills | 20:3abcf818be31 | 226 | m_currentSerialIntf++; |
ashleymills | 20:3abcf818be31 | 227 | } |
ashleymills | 20:3abcf818be31 | 228 | } |
ashleymills | 20:3abcf818be31 | 229 | else |
ashleymills | 20:3abcf818be31 | 230 | { |
ashleymills | 20:3abcf818be31 | 231 | if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) |
ashleymills | 20:3abcf818be31 | 232 | { |
ashleymills | 20:3abcf818be31 | 233 | return true; |
ashleymills | 20:3abcf818be31 | 234 | } |
ashleymills | 20:3abcf818be31 | 235 | } |
ashleymills | 20:3abcf818be31 | 236 | return false; |
ashleymills | 20:3abcf818be31 | 237 | } |
ashleymills | 20:3abcf818be31 | 238 | |
ashleymills | 20:3abcf818be31 | 239 | /*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 | 240 | { |
ashleymills | 20:3abcf818be31 | 241 | if( m_hasSwitched ) |
ashleymills | 20:3abcf818be31 | 242 | { |
ashleymills | 20:3abcf818be31 | 243 | if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) |
ashleymills | 20:3abcf818be31 | 244 | { |
ashleymills | 20:3abcf818be31 | 245 | m_endpointsToFetch--; |
ashleymills | 20:3abcf818be31 | 246 | return true; |
ashleymills | 20:3abcf818be31 | 247 | } |
ashleymills | 20:3abcf818be31 | 248 | } |
ashleymills | 20:3abcf818be31 | 249 | else |
ashleymills | 20:3abcf818be31 | 250 | { |
ashleymills | 20:3abcf818be31 | 251 | if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) |
ashleymills | 20:3abcf818be31 | 252 | { |
ashleymills | 20:3abcf818be31 | 253 | m_endpointsToFetch--; |
ashleymills | 20:3abcf818be31 | 254 | return true; |
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 | /*virtual*/ WAN_DONGLE_TYPE VodafoneK3773Initializer::getType() |
ashleymills | 20:3abcf818be31 | 261 | { |
ashleymills | 20:3abcf818be31 | 262 | return WAN_DONGLE_TYPE_VODAFONEK3773; |
ashleymills | 20:3abcf818be31 | 263 | } |
ashleymills | 20:3abcf818be31 | 264 | |
donatien | 8:0d1ec493842c | 265 | // NVIDIA (ICERA) /ZTE K3772-Z (Vodafone) |
donatien | 8:0d1ec493842c | 266 | // 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 | 267 | static uint8_t vodafone_k3772_z_switch_packet[] = { |
donatien | 8:0d1ec493842c | 268 | 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 | 269 | }; |
donatien | 8:0d1ec493842c | 270 | |
donatien | 8:0d1ec493842c | 271 | VodafoneK3772ZInitializer::VodafoneK3772ZInitializer(USBHost* pHost) : WANDongleInitializer(pHost) |
donatien | 8:0d1ec493842c | 272 | { |
donatien | 8:0d1ec493842c | 273 | |
donatien | 8:0d1ec493842c | 274 | } |
donatien | 8:0d1ec493842c | 275 | |
donatien | 8:0d1ec493842c | 276 | uint16_t VodafoneK3772ZInitializer::getMSDVid() { return 0x19D2; } |
donatien | 8:0d1ec493842c | 277 | uint16_t VodafoneK3772ZInitializer::getMSDPid() { return 0x1179; } |
donatien | 8:0d1ec493842c | 278 | |
donatien | 8:0d1ec493842c | 279 | uint16_t VodafoneK3772ZInitializer::getSerialVid() { return 0x19D2; } |
donatien | 8:0d1ec493842c | 280 | uint16_t VodafoneK3772ZInitializer::getSerialPid() { return 0x1181; } |
donatien | 8:0d1ec493842c | 281 | |
donatien | 8:0d1ec493842c | 282 | bool VodafoneK3772ZInitializer::switchMode(USBDeviceConnected* pDev) |
donatien | 8:0d1ec493842c | 283 | { |
donatien | 8:0d1ec493842c | 284 | for (int i = 0; i < pDev->getNbInterface(); i++) |
donatien | 8:0d1ec493842c | 285 | { |
donatien | 8:0d1ec493842c | 286 | if (pDev->getInterface(i)->intf_class == MSD_CLASS) |
donatien | 8:0d1ec493842c | 287 | { |
donatien | 9:c9e9817c398c | 288 | USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); |
donatien | 8:0d1ec493842c | 289 | if ( pEp != NULL ) |
donatien | 8:0d1ec493842c | 290 | { |
donatien | 8:0d1ec493842c | 291 | DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); |
donatien | 8:0d1ec493842c | 292 | m_pHost->bulkWrite(pDev, pEp, vodafone_k3772_z_switch_packet, 31); |
donatien | 8:0d1ec493842c | 293 | return true; |
donatien | 8:0d1ec493842c | 294 | } |
donatien | 8:0d1ec493842c | 295 | } |
donatien | 8:0d1ec493842c | 296 | } |
donatien | 8:0d1ec493842c | 297 | return false; |
donatien | 8:0d1ec493842c | 298 | } |
donatien | 8:0d1ec493842c | 299 | |
donatien | 9:c9e9817c398c | 300 | USBEndpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) |
donatien | 8:0d1ec493842c | 301 | { |
donatien | 8:0d1ec493842c | 302 | return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0); |
donatien | 8:0d1ec493842c | 303 | } |
donatien | 8:0d1ec493842c | 304 | |
donatien | 8:0d1ec493842c | 305 | int VodafoneK3772ZInitializer::getSerialPortCount() |
donatien | 8:0d1ec493842c | 306 | { |
donatien | 8:0d1ec493842c | 307 | return 2; |
donatien | 8:0d1ec493842c | 308 | } |
donatien | 8:0d1ec493842c | 309 | |
donatien | 8:0d1ec493842c | 310 | /*virtual*/ void VodafoneK3772ZInitializer::setVidPid(uint16_t vid, uint16_t pid) |
donatien | 8:0d1ec493842c | 311 | { |
donatien | 8:0d1ec493842c | 312 | if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) |
donatien | 8:0d1ec493842c | 313 | { |
donatien | 8:0d1ec493842c | 314 | m_hasSwitched = true; |
donatien | 8:0d1ec493842c | 315 | m_currentSerialIntf = 0; |
donatien | 8:0d1ec493842c | 316 | m_endpointsToFetch = 4; |
donatien | 8:0d1ec493842c | 317 | } |
donatien | 8:0d1ec493842c | 318 | else |
donatien | 8:0d1ec493842c | 319 | { |
donatien | 8:0d1ec493842c | 320 | m_hasSwitched = false; |
donatien | 8:0d1ec493842c | 321 | m_endpointsToFetch = 1; |
donatien | 8:0d1ec493842c | 322 | } |
donatien | 8:0d1ec493842c | 323 | } |
donatien | 8:0d1ec493842c | 324 | |
donatien | 8:0d1ec493842c | 325 | /*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 | 326 | { |
donatien | 8:0d1ec493842c | 327 | if( m_hasSwitched ) |
donatien | 8:0d1ec493842c | 328 | { |
donatien | 8:0d1ec493842c | 329 | DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); |
donatien | 8:0d1ec493842c | 330 | if( intf_class == 0x0A ) |
donatien | 8:0d1ec493842c | 331 | { |
donatien | 8:0d1ec493842c | 332 | if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) ) |
donatien | 8:0d1ec493842c | 333 | { |
donatien | 8:0d1ec493842c | 334 | m_currentSerialIntf++; |
donatien | 8:0d1ec493842c | 335 | return true; |
donatien | 8:0d1ec493842c | 336 | } |
donatien | 8:0d1ec493842c | 337 | m_currentSerialIntf++; |
donatien | 8:0d1ec493842c | 338 | } |
donatien | 8:0d1ec493842c | 339 | } |
donatien | 8:0d1ec493842c | 340 | else |
donatien | 8:0d1ec493842c | 341 | { |
donatien | 8:0d1ec493842c | 342 | if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) |
donatien | 8:0d1ec493842c | 343 | { |
donatien | 8:0d1ec493842c | 344 | return true; |
donatien | 8:0d1ec493842c | 345 | } |
donatien | 8:0d1ec493842c | 346 | } |
donatien | 8:0d1ec493842c | 347 | return false; |
donatien | 8:0d1ec493842c | 348 | } |
donatien | 8:0d1ec493842c | 349 | |
donatien | 8:0d1ec493842c | 350 | /*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 | 351 | { |
donatien | 8:0d1ec493842c | 352 | if( m_hasSwitched ) |
donatien | 8:0d1ec493842c | 353 | { |
donatien | 9:c9e9817c398c | 354 | DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); |
donatien | 8:0d1ec493842c | 355 | if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) |
donatien | 8:0d1ec493842c | 356 | { |
donatien | 8:0d1ec493842c | 357 | m_endpointsToFetch--; |
donatien | 8:0d1ec493842c | 358 | return true; |
donatien | 8:0d1ec493842c | 359 | } |
donatien | 8:0d1ec493842c | 360 | } |
donatien | 8:0d1ec493842c | 361 | else |
donatien | 8:0d1ec493842c | 362 | { |
donatien | 8:0d1ec493842c | 363 | if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) |
donatien | 8:0d1ec493842c | 364 | { |
donatien | 8:0d1ec493842c | 365 | m_endpointsToFetch--; |
donatien | 8:0d1ec493842c | 366 | return true; |
donatien | 8:0d1ec493842c | 367 | } |
donatien | 8:0d1ec493842c | 368 | } |
donatien | 8:0d1ec493842c | 369 | return false; |
donatien | 8:0d1ec493842c | 370 | } |
donatien | 8:0d1ec493842c | 371 | |
donatien | 8:0d1ec493842c | 372 | |
donatien | 8:0d1ec493842c | 373 | /*virtual*/ WAN_DONGLE_TYPE VodafoneK3772ZInitializer::getType() |
donatien | 8:0d1ec493842c | 374 | { |
donatien | 8:0d1ec493842c | 375 | return WAN_DONGLE_TYPE_VODAFONEK3772Z; |
donatien | 8:0d1ec493842c | 376 | } |