当前位置:   article > 正文

MT7628移植移远EC20驱动实现4G上网功能(绝大多数使用openwrt的设备通用)_mtk7628 openwrt 移远4g模块

mtk7628 openwrt 移远4g模块

我的上一篇文章中完成对MT7628固件的编译,本文是在固件编译通过的基础上移植EC20驱动的,固件编译问题请参考上文。

在讲解之前先介绍移远的EC20模块,该模块是目前较为成熟的4G模块,可向安装了Windows、Linux等设备的机器提供4G上网服务,移远同类产品中还有AG35模块,这个模块我之前在AM4378上移植过,当时花费了好多时间才移植成功,其实移远产品做得也不错,同类的模块移植方法基本是一样的。

废话不多说,下面开始讲述EC20驱动在MT7628上的移植过程。

 

第一步:

修改源码(注意:固件必须要先编译过一轮,否则没有build_dir目录)。此步骤必须细心修改,并认真核对。以下路径中的源文件均需要修改才能使用:

/home/user/openwrt-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.10.14/drivers/usb/serial/option.c

  1. //大概在532行,添加如下代码
  2. ......
  3. static const struct usb_device_id option_ids[] = {
  4. #if 1 //Added by Quectel
  5. { USB_DEVICE(0x05C6, 0x9090) }, /* Quectel UC15 */
  6. { USB_DEVICE(0x05C6, 0x9003) }, /* Quectel UC20 */
  7. { USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC25/EC20 R2.0 */
  8. { USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21 */
  9. { USB_DEVICE(0x05C6, 0x9215) }, /* Quectel EC20 */
  10. { USB_DEVICE(0x2C7C, 0x0191) }, /* Quectel EG91 */
  11. { USB_DEVICE(0x2C7C, 0x0195) }, /* Quectel EG95 */
  12. { USB_DEVICE(0x2C7C, 0x0306) }, /* Quectel EG06/EP06/EM06 */
  13. { USB_DEVICE(0x2C7C, 0x0296) }, /* Quectel BG96 */
  14. #endif
  15. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
  16. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
  17. ......
  1. //大概在1390行,插入以下代码
  2. ......
  3. #ifdef CONFIG_PM
  4. .suspend = usb_wwan_suspend,
  5. .resume = usb_wwan_resume,
  6. #if 1 //Added by Quectel
  7. .reset_resume = usb_wwan_resume,
  8. #endif
  9. #endif
  10. ......
  1. //在大约1459行,插入以下代码
  2. ......
  3. if (dev_desc->idVendor == cpu_to_le16(SAMSUNG_VENDOR_ID) &&
  4. dev_desc->idProduct == cpu_to_le16(SAMSUNG_PRODUCT_GT_B3730) &&
  5. iface_desc->bInterfaceClass != USB_CLASS_CDC_DATA)
  6. return -ENODEV;
  7. #if 1 //Added by Quectel
  8. //Quectel UC20's interface 4 can be used as USB Network device
  9. if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&
  10. serial->dev->descriptor.idProduct == cpu_to_le16(0x9003)
  11. && serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)return -ENODEV;
  12. //Quectel EC20's interface 4 can be used as USB Network device
  13. if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&
  14. serial->dev->descriptor.idProduct == cpu_to_le16(0x9215)
  15. && serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
  16. return -ENODEV;
  17. //Quectel EC25&EC21&EC20 R2.0&EG91&EG95&EG06&EP06&EM06&BG96's interface 4 can be
  18. //used as USB Network device
  19. if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)
  20. && serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
  21. return -ENODEV;
  22. #endif
  23. /* Store device id so we can use it during attach. */
  24. usb_set_serial_data(serial, (void *)id);
  25. ......

/home/user/openwrt-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.10.14/drivers/usb/serial/qcserial.c

  1. //大概在81行,注释以下代码
  2. //{USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */

/home/user/openwrt-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.10.14/drivers/net/usb/qmi_wwan.c

  1. //大概在617行,注释以下代码
  2. //{QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */
  1. //在大概436行,插入以下代码
  2. ......
  3. static const struct usb_device_id products[] = {
  4. #if 1 //Added by Quectel
  5. #ifndef QMI_FIXED_INTF
  6. /* map QMI/wwan function by a fixed interface number */
  7. #define QMI_FIXED_INTF(vend, prod, num) \
  8. .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  9. USB_DEVICE_ID_MATCH_INT_INFO, \
  10. .idVendor = vend, \
  11. .idProduct = prod, \
  12. .bInterfaceClass = 0xff, \
  13. .bInterfaceSubClass = 0xff, \
  14. .bInterfaceProtocol = 0xff, \
  15. .driver_info = (unsigned long)&qmi_wwan_force_int##num,
  16. #endif
  17. { QMI_FIXED_INTF(0x05C6, 0x9003, 4) }, /* Quectel UC20 */
  18. { QMI_FIXED_INTF(0x2C7C, 0x0125, 4) }, /* Quectel EC25/EC20 R2.0 */
  19. { QMI_FIXED_INTF(0x2C7C, 0x0121, 4) }, /* Quectel EC21 */
  20. { QMI_FIXED_INTF(0x05C6, 0x9215, 4) }, /* Quectel EC20 */
  21. { QMI_FIXED_INTF(0x2C7C, 0x0191, 4) }, /* Quectel EG91 */
  22. { QMI_FIXED_INTF(0x2C7C, 0x0195, 4) }, /* Quectel EG95 */
  23. { QMI_FIXED_INTF(0x2C7C, 0x0306, 4) }, /* Quectel EG06/EP06/EM06 */
  24. { QMI_FIXED_INTF(0x2C7C, 0x0296, 4) }, /* Quectel BG96 */
  25. #endif
  26. ......
  1. //在文件的开头处插入如下代码
  2. ......
  3. #include <linux/usb/usbnet.h>
  4. #include <linux/usb/cdc-wdm.h>
  5. #if 1 //Added by Quectel
  6. #include <linux/etherdevice.h>
  7. struct sk_buff *qmi_wwan_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
  8. {
  9. if (dev->udev->descriptor.idVendor != cpu_to_le16(0x2C7C))
  10. return skb;
  11. // Skip Ethernet header from message
  12. if (skb_pull(skb, ETH_HLEN)) {
  13. return skb;
  14. } else {
  15. dev_err(&dev->intf->dev, "Packet Dropped ");
  16. }
  17. // Filter the packet out, release it
  18. dev_kfree_skb_any(skb);
  19. return NULL;
  20. }
  21. #include <linux/version.h>
  22. #if (LINUX_VERSION_CODE < KERNEL_VERSION( 3,9,1 ))
  23. static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  24. {
  25. __be16 proto;
  26. if (dev->udev->descriptor.idVendor != cpu_to_le16(0x2C7C))
  27. return 1;/* This check is no longer done by usbnet */
  28. if (skb->len < dev->net->hard_header_len)
  29. return 0;
  30. switch (skb->data[0] & 0xf0) {
  31. case 0x40:
  32. proto = htons(ETH_P_IP);
  33. break;
  34. case 0x60:
  35. proto = htons(ETH_P_IPV6);
  36. break;
  37. case 0x00:
  38. if (is_multicast_ether_addr(skb->data))
  39. return 1;
  40. /* possibly bogus destination - rewrite just in case */
  41. skb_reset_mac_header(skb);
  42. goto fix_dest;
  43. default:
  44. /* pass along other packets without modifications */
  45. return 1;
  46. }
  47. if (skb_headroom(skb) < ETH_HLEN)
  48. return 0;
  49. skb_push(skb, ETH_HLEN);
  50. skb_reset_mac_header(skb);
  51. eth_hdr(skb)->h_proto = proto;
  52. memset(eth_hdr(skb)->h_source, 0, ETH_ALEN);
  53. fix_dest:
  54. memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN);
  55. return 1;
  56. }
  57. /* very simplistic detection of IPv4 or IPv6 headers */
  58. static bool possibly_iphdr(const char *data)
  59. {
  60. return (data[0] & 0xd0) == 0x40;
  61. }
  62. #endif
  63. #endif
  64. ......
  1. //在大概395行,插入如下代码
  2. ......
  3. #if 1 //Added by Quectel
  4. if (dev->udev->descriptor.idVendor == cpu_to_le16(0x2C7C)) {
  5. dev_info(&intf->dev, "Quectel EC25&EC21&EC20 R2.0&EG91&EG95&EG06&EP06&EM06&BG96 work on RawIP mode\n");
  6. dev->net->flags |= IFF_NOARP;
  7. #if (LINUX_VERSION_CODE < KERNEL_VERSION( 3,9,1 ))
  8. /* make MAC addr easily distinguishable from an IP header */
  9. if (possibly_iphdr(dev->net->dev_addr)) {
  10. dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */
  11. dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */
  12. }
  13. #endif
  14. usb_control_msg(
  15. interface_to_usbdev(intf),
  16. usb_sndctrlpipe(interface_to_usbdev(intf), 0),
  17. 0x22, //USB_CDC_REQ_SET_CONTROL_LINE_STATE
  18. 0x21, //USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE
  19. 1, //active CDC DTR
  20. intf->cur_altsetting->desc.bInterfaceNumber,
  21. NULL, 0, 100);
  22. }
  23. #endif
  24. ......
  1. //在大约504行,插入如下代码
  2. ......
  3. static const struct driver_info qmi_wwan_info = {
  4. .description = "WWAN/QMI device",
  5. .flags = FLAG_WWAN,
  6. .bind = qmi_wwan_bind,
  7. .unbind = qmi_wwan_unbind,
  8. .manage_power = qmi_wwan_manage_power,
  9. .rx_fixup = qmi_wwan_rx_fixup,
  10. #if 1 //Added by Quectel
  11. .tx_fixup = qmi_wwan_tx_fixup,
  12. #endif
  13. ......

/home/lusy/openwrt-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.10.14/drivers/usb/serial/usb_wwan.c

  1. //大概在460行,插入如下代码
  2. ......
  3. usb_fill_bulk_urb(urb, serial->dev,
  4. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  5. buf, len, callback, ctx);
  6. #if 1 //Added by Quectel for Zero Packet
  7. if (dir == USB_DIR_OUT) {
  8. struct usb_device_descriptor *desc = &serial->dev->descriptor;
  9. if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9090))
  10. urb->transfer_flags |= URB_ZERO_PACKET;
  11. if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9003))
  12. urb->transfer_flags |= URB_ZERO_PACKET;
  13. if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9215))
  14. urb->transfer_flags |= URB_ZERO_PACKET;
  15. if (desc->idVendor == cpu_to_le16(0x2C7C))
  16. urb->transfer_flags |= URB_ZERO_PACKET;
  17. }
  18. #endif
  19. return urb;
  20. ......

 

第二步:

修改配置,在内核中添加一些选项来支持EC20。这里参考了别人的博客,网址如下:https://blog.csdn.net/hunzhangzui9837/article/details/85916965

#make menuconfig

Kernel modules->USB Support

照着图片配置就行。。。

Network->

将以下选项编译进内核,但是我在我的make menuconfig中找不到wwan,先不管它,有就勾上。

wwan

chat

ppp

uqmi

Utilities->

将以下选项编译进内核,同样没找到comgt-ncm,不管它

comgt

comgt-ncm

usb-modeswitch

Luci->

1.Collections

luci

3.Applications

luci-app-multiwan

luci-app-qos

6.Protocols

luci-proto-3g

luci-proto-ppp

全都配置完了,开始编译

#make V=s

没有问题,全部编译成功。

 

第三步:

将编译好的固件烧入开发板。固件在/home/user/openwrt-sdk/bin/ramips路径下,名称为openwrt-ramips-mt7628-mt7628-squashfs-sysupgrade.bin。

启动开发板,先用

#ifconfig

查看一下当前ip地址,然后将ip地址复制到浏览器打开,即可通过LuCI登录板子进行配置。

选择如上图所示进入固件更新页面,进入如下页面

在这个页面更新固件就可以了。

更新完成后,就可以将EC20通过USB插入开发板了,如果你的驱动移植成功,将会看到如下log:

#cd /dev

查看一下是否有这几个文件。

 

第四步:

怎么通过4G模块上网。先进入LuCI页面。

如上图,进入接口配置。这里需要添加一个接口,下图已经添加好了,我下面教大家怎么添加。

点击Add new interface,名字自己起一个,选DHCP,选wwan0,如下图所示。

完成后记得修改一下这个接口的防火墙,如下图。

保存退出,最好板子也重启一下。

再次进入板子,输入

#ifconfig

就能看到你新加的接口了,4G网络正常的话这个接口应能获取到IP地址。

#ping www.baidu.com

PING www.baidu.com (183.232.231.172): 56 data bytes
64 bytes from 183.232.231.172: seq=0 ttl=53 time=131.616 ms
64 bytes from 183.232.231.172: seq=1 ttl=53 time=107.725 ms
64 bytes from 183.232.231.172: seq=2 ttl=53 time=112.723 ms
64 bytes from 183.232.231.172: seq=3 ttl=53 time=113.865 ms

OK,大功告成!

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/311785
推荐阅读
相关标签
  

闽ICP备14008679号