USB Host Library for Sprint Dongles
Fork of USBHostWANDongleSprint by
USB3GModule/WANDongleInitializer.cpp@8:65cd51339647, 2012-11-30 (annotated)
- Committer:
- donatien
- Date:
- Fri Nov 30 13:08:13 2012 +0000
- Revision:
- 8:65cd51339647
- Parent:
- 6:aaf432a6819b
Support for MC5728V dongle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bfed5767d0a5 | 1 | /* Copyright (c) 2010-2012 mbed.org, MIT License |
donatien | 0:bfed5767d0a5 | 2 | * |
donatien | 0:bfed5767d0a5 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:bfed5767d0a5 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
donatien | 0:bfed5767d0a5 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
donatien | 0:bfed5767d0a5 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
donatien | 0:bfed5767d0a5 | 7 | * Software is furnished to do so, subject to the following conditions: |
donatien | 0:bfed5767d0a5 | 8 | * |
donatien | 0:bfed5767d0a5 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:bfed5767d0a5 | 10 | * substantial portions of the Software. |
donatien | 0:bfed5767d0a5 | 11 | * |
donatien | 0:bfed5767d0a5 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:bfed5767d0a5 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:bfed5767d0a5 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:bfed5767d0a5 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:bfed5767d0a5 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:bfed5767d0a5 | 17 | */ |
donatien | 0:bfed5767d0a5 | 18 | |
donatien | 3:9ec92dd8a8cb | 19 | #define __DEBUG__ 0 |
donatien | 0:bfed5767d0a5 | 20 | #ifndef __MODULE__ |
donatien | 0:bfed5767d0a5 | 21 | #define __MODULE__ "WANDongleInitializer.cpp" |
donatien | 0:bfed5767d0a5 | 22 | #endif |
donatien | 0:bfed5767d0a5 | 23 | |
donatien | 0:bfed5767d0a5 | 24 | #include "core/dbg.h" |
donatien | 0:bfed5767d0a5 | 25 | |
donatien | 0:bfed5767d0a5 | 26 | #include <cstdint> |
donatien | 0:bfed5767d0a5 | 27 | using std::uint16_t; |
donatien | 0:bfed5767d0a5 | 28 | |
donatien | 0:bfed5767d0a5 | 29 | #include "WANDongleInitializer.h" |
donatien | 0:bfed5767d0a5 | 30 | |
donatien | 0:bfed5767d0a5 | 31 | WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost) |
donatien | 0:bfed5767d0a5 | 32 | { |
donatien | 0:bfed5767d0a5 | 33 | |
donatien | 0:bfed5767d0a5 | 34 | } |
donatien | 0:bfed5767d0a5 | 35 | |
donatien | 0:bfed5767d0a5 | 36 | WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost) |
donatien | 0:bfed5767d0a5 | 37 | { |
donatien | 0:bfed5767d0a5 | 38 | static Sprint598UInitializer sprint598U(pHost); |
donatien | 8:65cd51339647 | 39 | static SprintMC5728VInitializer sprintMC5728V(pHost); |
donatien | 8:65cd51339647 | 40 | const static WANDongleInitializer* list[] = { &sprint598U, &sprintMC5728V, NULL }; |
donatien | 0:bfed5767d0a5 | 41 | return (WANDongleInitializer**)list; |
donatien | 0:bfed5767d0a5 | 42 | } |
donatien | 0:bfed5767d0a5 | 43 | |
donatien | 0:bfed5767d0a5 | 44 | //Sierra Wireless 598U (Sprint) |
donatien | 0:bfed5767d0a5 | 45 | Sprint598UInitializer::Sprint598UInitializer(USBHost* pHost) : WANDongleInitializer(pHost) |
donatien | 0:bfed5767d0a5 | 46 | { |
donatien | 0:bfed5767d0a5 | 47 | |
donatien | 0:bfed5767d0a5 | 48 | } |
donatien | 0:bfed5767d0a5 | 49 | |
donatien | 0:bfed5767d0a5 | 50 | uint16_t Sprint598UInitializer::getMSDVid() { return 0x1199; } |
donatien | 0:bfed5767d0a5 | 51 | uint16_t Sprint598UInitializer::getMSDPid() { return 0x0FFF; } //0x0f25? |
donatien | 0:bfed5767d0a5 | 52 | |
donatien | 0:bfed5767d0a5 | 53 | uint16_t Sprint598UInitializer::getSerialVid() { return 0x1199; } |
donatien | 0:bfed5767d0a5 | 54 | uint16_t Sprint598UInitializer::getSerialPid() { return 0x0025; } |
donatien | 0:bfed5767d0a5 | 55 | |
donatien | 0:bfed5767d0a5 | 56 | bool Sprint598UInitializer::switchMode(USBDeviceConnected* pDev) |
donatien | 0:bfed5767d0a5 | 57 | { |
donatien | 0:bfed5767d0a5 | 58 | DBG("Device %p found, will now try to switch into serial mode", (void *)pDev); |
donatien | 0:bfed5767d0a5 | 59 | m_pHost->controlWrite(pDev, /*requestType = */ 0x40, /*request = */ 0x0B, /*value = */ 0x00000001, /*index = */ 0, /*buf = */ NULL, /*len = */ 0); |
donatien | 0:bfed5767d0a5 | 60 | return true; |
donatien | 0:bfed5767d0a5 | 61 | } |
donatien | 0:bfed5767d0a5 | 62 | |
donatien | 1:3bcca949166d | 63 | USBEndpoint* Sprint598UInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) |
donatien | 0:bfed5767d0a5 | 64 | { |
donatien | 5:99f453c4756b | 65 | return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); |
donatien | 0:bfed5767d0a5 | 66 | } |
donatien | 0:bfed5767d0a5 | 67 | |
donatien | 0:bfed5767d0a5 | 68 | int Sprint598UInitializer::getSerialPortCount() |
donatien | 0:bfed5767d0a5 | 69 | { |
donatien | 4:cd9864d1db52 | 70 | return 1; |
donatien | 0:bfed5767d0a5 | 71 | } |
donatien | 0:bfed5767d0a5 | 72 | |
donatien | 0:bfed5767d0a5 | 73 | /*virtual*/ void Sprint598UInitializer::setVidPid(uint16_t vid, uint16_t pid) |
donatien | 0:bfed5767d0a5 | 74 | { |
donatien | 0:bfed5767d0a5 | 75 | if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) |
donatien | 0:bfed5767d0a5 | 76 | { |
donatien | 0:bfed5767d0a5 | 77 | m_hasSwitched = true; |
donatien | 0:bfed5767d0a5 | 78 | m_currentSerialIntf = 0; |
donatien | 4:cd9864d1db52 | 79 | m_currentEndpoint = 0; |
donatien | 0:bfed5767d0a5 | 80 | } |
donatien | 0:bfed5767d0a5 | 81 | else |
donatien | 0:bfed5767d0a5 | 82 | { |
donatien | 0:bfed5767d0a5 | 83 | m_hasSwitched = false; |
donatien | 0:bfed5767d0a5 | 84 | } |
donatien | 0:bfed5767d0a5 | 85 | } |
donatien | 0:bfed5767d0a5 | 86 | |
donatien | 0:bfed5767d0a5 | 87 | /*virtual*/ bool Sprint598UInitializer::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 | 0:bfed5767d0a5 | 88 | { |
donatien | 0:bfed5767d0a5 | 89 | if( m_hasSwitched ) |
donatien | 0:bfed5767d0a5 | 90 | { |
donatien | 0:bfed5767d0a5 | 91 | DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); |
donatien | 2:34c976009b70 | 92 | if( intf_class == 0xFF ) |
donatien | 0:bfed5767d0a5 | 93 | { |
donatien | 3:9ec92dd8a8cb | 94 | if( (m_currentSerialIntf == 0) ) |
donatien | 0:bfed5767d0a5 | 95 | { |
donatien | 0:bfed5767d0a5 | 96 | m_currentSerialIntf++; |
donatien | 0:bfed5767d0a5 | 97 | return true; |
donatien | 0:bfed5767d0a5 | 98 | } |
donatien | 0:bfed5767d0a5 | 99 | m_currentSerialIntf++; |
donatien | 0:bfed5767d0a5 | 100 | } |
donatien | 0:bfed5767d0a5 | 101 | } |
donatien | 0:bfed5767d0a5 | 102 | return false; |
donatien | 0:bfed5767d0a5 | 103 | } |
donatien | 0:bfed5767d0a5 | 104 | |
donatien | 0:bfed5767d0a5 | 105 | /*virtual*/ bool Sprint598UInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
donatien | 0:bfed5767d0a5 | 106 | { |
donatien | 0:bfed5767d0a5 | 107 | if( m_hasSwitched ) |
donatien | 0:bfed5767d0a5 | 108 | { |
donatien | 0:bfed5767d0a5 | 109 | DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir); |
donatien | 4:cd9864d1db52 | 110 | if(type == BULK_ENDPOINT) |
donatien | 0:bfed5767d0a5 | 111 | { |
donatien | 6:aaf432a6819b | 112 | if( (m_currentEndpoint >= 0) && (m_currentEndpoint < 2) ) |
donatien | 3:9ec92dd8a8cb | 113 | { |
donatien | 4:cd9864d1db52 | 114 | m_currentEndpoint++; |
donatien | 3:9ec92dd8a8cb | 115 | return true; |
donatien | 3:9ec92dd8a8cb | 116 | } |
donatien | 3:9ec92dd8a8cb | 117 | else |
donatien | 3:9ec92dd8a8cb | 118 | { |
donatien | 4:cd9864d1db52 | 119 | m_currentEndpoint++; |
donatien | 3:9ec92dd8a8cb | 120 | } |
donatien | 0:bfed5767d0a5 | 121 | } |
donatien | 0:bfed5767d0a5 | 122 | } |
donatien | 0:bfed5767d0a5 | 123 | return false; |
donatien | 0:bfed5767d0a5 | 124 | } |
donatien | 0:bfed5767d0a5 | 125 | |
donatien | 0:bfed5767d0a5 | 126 | |
donatien | 0:bfed5767d0a5 | 127 | /*virtual*/ WAN_DONGLE_TYPE Sprint598UInitializer::getType() |
donatien | 0:bfed5767d0a5 | 128 | { |
donatien | 0:bfed5767d0a5 | 129 | return WAN_DONGLE_TYPE_SPRINT598U; |
donatien | 0:bfed5767d0a5 | 130 | } |
donatien | 8:65cd51339647 | 131 | |
donatien | 8:65cd51339647 | 132 | //Sierra Wireless MC5728V (Sprint) |
donatien | 8:65cd51339647 | 133 | SprintMC5728VInitializer::SprintMC5728VInitializer(USBHost* pHost) : WANDongleInitializer(pHost) |
donatien | 8:65cd51339647 | 134 | { |
donatien | 8:65cd51339647 | 135 | |
donatien | 8:65cd51339647 | 136 | } |
donatien | 8:65cd51339647 | 137 | |
donatien | 8:65cd51339647 | 138 | uint16_t SprintMC5728VInitializer::getMSDVid() { return 0x1199; } |
donatien | 8:65cd51339647 | 139 | uint16_t SprintMC5728VInitializer::getMSDPid() { return 0x0000; } //No MSD mode (presumably) |
donatien | 8:65cd51339647 | 140 | |
donatien | 8:65cd51339647 | 141 | uint16_t SprintMC5728VInitializer::getSerialVid() { return 0x1199; } |
donatien | 8:65cd51339647 | 142 | uint16_t SprintMC5728VInitializer::getSerialPid() { return 0x0028; } |
donatien | 8:65cd51339647 | 143 | |
donatien | 8:65cd51339647 | 144 | bool SprintMC5728VInitializer::switchMode(USBDeviceConnected* pDev) |
donatien | 8:65cd51339647 | 145 | { |
donatien | 8:65cd51339647 | 146 | return true; |
donatien | 8:65cd51339647 | 147 | } |
donatien | 8:65cd51339647 | 148 | |
donatien | 8:65cd51339647 | 149 | USBEndpoint* SprintMC5728VInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) |
donatien | 8:65cd51339647 | 150 | { |
donatien | 8:65cd51339647 | 151 | return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); |
donatien | 8:65cd51339647 | 152 | } |
donatien | 8:65cd51339647 | 153 | |
donatien | 8:65cd51339647 | 154 | int SprintMC5728VInitializer::getSerialPortCount() |
donatien | 8:65cd51339647 | 155 | { |
donatien | 8:65cd51339647 | 156 | return 1; |
donatien | 8:65cd51339647 | 157 | } |
donatien | 8:65cd51339647 | 158 | |
donatien | 8:65cd51339647 | 159 | /*virtual*/ void SprintMC5728VInitializer::setVidPid(uint16_t vid, uint16_t pid) |
donatien | 8:65cd51339647 | 160 | { |
donatien | 8:65cd51339647 | 161 | m_currentSerialIntf = 0; |
donatien | 8:65cd51339647 | 162 | m_currentEndpoint = 0; |
donatien | 8:65cd51339647 | 163 | } |
donatien | 8:65cd51339647 | 164 | |
donatien | 8:65cd51339647 | 165 | /*virtual*/ bool SprintMC5728VInitializer::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:65cd51339647 | 166 | { |
donatien | 8:65cd51339647 | 167 | DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); |
donatien | 8:65cd51339647 | 168 | if( intf_class == 0xFF ) |
donatien | 8:65cd51339647 | 169 | { |
donatien | 8:65cd51339647 | 170 | if( (m_currentSerialIntf == 0) ) |
donatien | 8:65cd51339647 | 171 | { |
donatien | 8:65cd51339647 | 172 | m_currentSerialIntf++; |
donatien | 8:65cd51339647 | 173 | return true; |
donatien | 8:65cd51339647 | 174 | } |
donatien | 8:65cd51339647 | 175 | m_currentSerialIntf++; |
donatien | 8:65cd51339647 | 176 | } |
donatien | 8:65cd51339647 | 177 | return false; |
donatien | 8:65cd51339647 | 178 | } |
donatien | 8:65cd51339647 | 179 | |
donatien | 8:65cd51339647 | 180 | /*virtual*/ bool SprintMC5728VInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
donatien | 8:65cd51339647 | 181 | { |
donatien | 8:65cd51339647 | 182 | DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir); |
donatien | 8:65cd51339647 | 183 | if(type == BULK_ENDPOINT) |
donatien | 8:65cd51339647 | 184 | { |
donatien | 8:65cd51339647 | 185 | if( (m_currentEndpoint >= 0) && (m_currentEndpoint < 2) ) |
donatien | 8:65cd51339647 | 186 | { |
donatien | 8:65cd51339647 | 187 | m_currentEndpoint++; |
donatien | 8:65cd51339647 | 188 | return true; |
donatien | 8:65cd51339647 | 189 | } |
donatien | 8:65cd51339647 | 190 | else |
donatien | 8:65cd51339647 | 191 | { |
donatien | 8:65cd51339647 | 192 | m_currentEndpoint++; |
donatien | 8:65cd51339647 | 193 | } |
donatien | 8:65cd51339647 | 194 | } |
donatien | 8:65cd51339647 | 195 | return false; |
donatien | 8:65cd51339647 | 196 | } |
donatien | 8:65cd51339647 | 197 | |
donatien | 8:65cd51339647 | 198 | |
donatien | 8:65cd51339647 | 199 | /*virtual*/ WAN_DONGLE_TYPE SprintMC5728VInitializer::getType() |
donatien | 8:65cd51339647 | 200 | { |
donatien | 8:65cd51339647 | 201 | return WAN_DONGLE_TYPE_SPRINTMC5728V; |
donatien | 8:65cd51339647 | 202 | } |