UbloxGSMModemInitializer.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "UbloxGSMModemInitializer.h"
  19. #include "core/dbg.h"
  20. #define __DEBUG__ 0
  21. #ifndef __MODULE__
  22. #define __MODULE__ "UbloxGSMModemInitializer.cpp"
  23. #endif
  24. //-----------------------------------------------------------------------
  25. // mamm, u-blox Modem
  26. //-----------------------------------------------------------------------
  27. UbloxGSMModemInitializer::UbloxGSMModemInitializer(USBHost* pHost) : WANDongleInitializer(pHost)
  28. {
  29. }
  30. uint16_t UbloxGSMModemInitializer::getMSDVid() { return 0x1546; }
  31. uint16_t UbloxGSMModemInitializer::getMSDPid() { return 0x0000; }
  32. uint16_t UbloxGSMModemInitializer::getSerialVid() { return 0x1546; }
  33. uint16_t UbloxGSMModemInitializer::getSerialPid() { return 0x1102; }
  34. bool UbloxGSMModemInitializer::switchMode(USBDeviceConnected* pDev)
  35. {
  36. for (int i = 0; i < pDev->getNbIntf(); i++)
  37. {
  38. if (pDev->getInterface(i)->intf_class == MSD_CLASS)
  39. {
  40. USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT);
  41. if ( pEp != NULL )
  42. {
  43. ERR("MSD descriptor found on device %p, intf %d", (void *)pDev, i);
  44. }
  45. }
  46. }
  47. return false;
  48. }
  49. #define UBX_SERIALCOUNT 7
  50. int UbloxGSMModemInitializer::getSerialPortCount()
  51. {
  52. return UBX_SERIALCOUNT;
  53. }
  54. /*virtual*/ void UbloxGSMModemInitializer::setVidPid(uint16_t vid, uint16_t pid)
  55. {
  56. if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
  57. {
  58. m_hasSwitched = true;
  59. m_currentSerialIntf = 0;
  60. m_endpointsToFetch = UBX_SERIALCOUNT*2;
  61. }
  62. else
  63. {
  64. m_hasSwitched = false;
  65. m_endpointsToFetch = 1;
  66. }
  67. }
  68. /*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
  69. {
  70. if( m_hasSwitched )
  71. {
  72. DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol);
  73. if( intf_class == 0x0A )
  74. {
  75. if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) )
  76. {
  77. m_serialIntfMap[m_currentSerialIntf++] = intf_nb;
  78. return true;
  79. }
  80. m_currentSerialIntf++;
  81. }
  82. }
  83. else
  84. {
  85. if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
  86. {
  87. return true;
  88. }
  89. }
  90. return false;
  91. }
  92. /*virtual*/ bool UbloxGSMModemInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
  93. {
  94. if( m_hasSwitched )
  95. {
  96. DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir);
  97. if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
  98. {
  99. m_endpointsToFetch--;
  100. return true;
  101. }
  102. }
  103. else
  104. {
  105. if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch )
  106. {
  107. m_endpointsToFetch--;
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113. /*virtual*/ int UbloxGSMModemInitializer::getType()
  114. {
  115. return WAN_DONGLE_TYPE_UBLOX_LISAU200;
  116. }