概述
项目中4G模块开发工作记录:
模块组成:
4G模组硬件结构:ATMET A5(ARM-V7) + SIM7600CE_CU模组
4G模组软件结构:Linux kernel==5.4.53 + LE11B13SIM7600M21_CUS_HX
实现流程:
- 上电为SIM7600模块开机
- NDIS拨号为主板提供上网,为wwan0获取IP
- 把模组设置为NAT,并为eth0加上DHCP
附:桥接本地物理接口eth0 到 wwan0
主体架构
具体流程:
1. 开机
严格按照芯讯通手册通过POWERKEY引脚开机:
bool SIM7600_PWR_ON(SIMCOM_HANDLE *pHandle, bool isTest)
{
int i,j;
pHandle->pPinEnable();
if(isTest)
{
if(pHandle->pGetSTATUS_Pin() != SIMCOM_L_LEVEL) //开机脚已经是高电平了
{
SIM7600_PWR_DOWN(pHandle, FALSE);
}
for(i = 0; i < 2; i++)
{
pHandle->pSetPWRKEY_Pin(SIMCOM_L_LEVEL);
vTaskDelay( 50 / portTICK_RATE_MS );
pHandle->pSetPWRKEY_Pin(SIMCOM_H_LEVEL);
for(j = 0; j < 30; j++)
{
if(pHandle->pGetSTATUS_Pin() != SIMCOM_L_LEVEL) //开机脚已经是高电平了
{
DEBUG_INFO("[SIMCOM]:STATUS level is already highrn");
return TRUE;
}
vTaskDelay( 1000 / portTICK_RATE_MS );
}
}
return FALSE;
}
else
{
pHandle->pSetPWRKEY_Pin(SIMCOM_L_LEVEL);
vTaskDelay( 50 / portTICK_RATE_MS );
pHandle->pSetPWRKEY_Pin(SIMCOM_H_LEVEL);
vTaskDelay( 1000 / portTICK_RATE_MS );
return TRUE;
}
}
2.拨号上网
参考文章:https://www.waveshare.net/study/article-929-1.html
<1> 将sim7500_sin7600_wwan0.c编译进内核
<2> 手动移除高通默认的cdc-wwan0,再进行NDIS拨号
以下为主要操作:
**移除高通cdc-wwan,安装sim7500-sim7600-wwan**
$ apt-get remove kernel-module-qmi-wwan
$ apt-get update && apt-get install kernel-module-sim7500-sim7600-wwan
**查看SIM7600模块是否开机成功,是否拥有wwan0**
$ ifconfig -a
**使wwan0 处于UP状态**
$ ifconfig wwan0 up
**使用microcom工具打开 /dev/ttyUSB2,并发送拨号指令**
$ microcom /dev/ttyUSB2
$ ati
$ AT$QCRMCALL=1,1
eg:
[root@Matrix_03c544 usb]#microcom /dev/ttyUSB2
ati
Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600CE-CU
Revision: SIM7600M21_V1.1
IMEI: 866323033216424
+GCAP: +CGSM
OK
AT$QCRMCALL=1,1
$QCRMCALL: 1, V4
OK
成功后使用ctrl+x退出该工具
**利用DHCP为wwan0网卡获取IP、DNS等信息**
$ udhcpc -i wwan0
eg:
[root@Matrix_03c544 usb]#udhcpc -i wwan0
udhcpc: started, v1.31.1
run-parts: /etc/udhcpc.d/00avahi-autoipd exited with return code 1
udhcpc: sending discover
udhcpc: sending select for 10.128.45.103
udhcpc: lease of 10.128.45.103 obtained, lease time 7200
run-parts: /etc/udhcpc.d/00avahi-autoipd exited with return code 1
/etc/udhcpc.d/50default: Adding DNS 221.11.1.67
/etc/udhcpc.d/50default: Adding DNS 221.11.1.68
**查看网关信息,删除多余网关**
$ route -n
$ route delete default gw 192.168.11.3
$ route delete default gw 192.168.1.1 //route add default gw X.X.X.X
**ping外网地址,能ping通说明上网成功**
$ ping www.baidu.com
$ ping 1.1.1.1
3 DHCP + NAT
3.1 从repostiory上下载dhcp-server package
$ apt-get update
$ apt-get install dhcp-server
3.2 修改或新建/etc/dhcp/dhcpd.conf的内容,如下:
参考文章:
http://linux.vbird.org/linux_server/0340dhcp.php#client_win
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#subnet 192.168.11.0 netmask 255.255.255.0 {
# range 192.168.11.200 192.168.11.210;
# option domain-name-servers 192.168.11.1;
# option domain-name "miner.example.org";
# option routers 192.168.11.1;
# option broadcast-address 192.168.11.255;
# default-lease-time 600;
# max-lease-time 7200;
#}
log-facility local7;
default-lease-time 86400;
option domain-name "internal.example.org";
option domain-search "example.org";
option domain-name-servers 1.1.1.1, 208.67.222.220;
option time-servers asia.pool.ntp.org;
option ntp-servers asia.pool.ntp.org;
subnet 192.168.11.0 netmask 255.255.255.0 {
range 192.168.11.200 192.168.11.210;
option routers 192.168.11.1;
}
继续再把模块eth0设为192.168.11.1(重要)
3.3 /etc/default/dhcp-server 中内容修改为:
INTERFACES="eth0"
3.4 启动dhcp-server的启动脚本
/etc/init.d/dhcp-server start
3.5 设置打开NAT,并设置iptables规则
参考文章:
https://www.cnblogs.com/huangjacky/archive/2013/04/24/3041339.html
https://blog.csdn.net/gui951753/article/details/79593307
https://blog.csdn.net/freeking101/article/details/77962312
$ apt-get install kernel-module-xt-nat kernel-module-xt-masquerade
$ echo "1" > /proc/sys/net/ipv4/ip_forward
$ iptables -t nat -A POSTROUTING -j MASQUERADE
(bak)iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
成果测试
pc与模块直连,模块为pc分配IP地址
网络测试
附 :
将eth0桥接至wwan0,使外部主机可通过模块上网
参考文章:
https://www.cnblogs.com/dpf-10/p/10682128.html
https://blog.csdn.net/xiaoliuliu2050/article/details/53485753
http://www.360doc.com/content/10/0622/16/1059940_34608732.shtml
**安装brctl**
$ apt-get install bridge-utils
**桥接本地网卡eth0到4G网卡wwan0**
$ brctl addbr br0 (add bridge)
$ brctl addif br0 eth0 (add interface to bridge)
$ brctl addif br0 wwan0 (add interface to bridge)
$ brctl show (show a list of bridges)
[root@Matrix_03c544 usb]#brctl show
bridge name bridge id STP enabled interfaces
br0 8000.00134803c544 no eth0
wwan0
$ brctl setageing br0 0 (set ageing time)
**删除网桥**
$ brctl delif br0 eth0
$ brctl delif br0 wwan0
$ ifconfig br0 down
$ brctl delbr br0
最后
以上就是舒适路人为你收集整理的PC通过4G模块上网实现流程记录的全部内容,希望文章能够帮你解决PC通过4G模块上网实现流程记录所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复