#过年不停更# Openharmony 网络-通过第三方库实现IP自动配置(L2) 原创

发布于 2022-2-13 16:42
浏览
5收藏

【春节不停更,此文正在参加「星光计划-春节更帖活动」】

@toc

简介

Openharmony的Hi3516DV300目前插上网线不能上网,需要配置网络。

手动配置

具体的IP地址要根据自己实际情况确定。更详细操作可以参考:https://harmonyos.51cto.com/posts/10210

  • 配IP和子网掩码
    ifconfig eth0 192.168.1.200 netmask 255.255.255.0
  • 配网关
    route add default gw 192.168.1.1
  • 启动网卡
    ifconfig eth0 up

动态获取

动态获取用到第三方组件toybox, 需要把其dhcp功能开放出来。

代码修改

  • 修改third_party/toybox/BUILD.gn
  import("//build/ohos.gni") # L2的分支

  ohos_executable("toybox") {
	...
	"toys/pending/dhcp.c", # dhcp 添加到toybox编译中去
	...
  }
  ...
  symlink_target_name = [
	...
	"dhcp", # 添加dhcp到toybox的链接
	...
  ]
  • 修改third_party/toybox/generated/config.h
// 修改前
#define CFG_DHCP 0
#define USE_DHCP(...)
// 修改后
#define CFG_DHCP 1
#define USE_DHCP(...) __VA_ARGS__
  • 修改third_party/toybox/generated/flags.h
// 修改前
#ifndef TT
#define TT this.dhcp
#endif
#define FLAG_f (FORCED_FLAG<<0)
#define FLAG_b (FORCED_FLAG<<1)
#define FLAG_n (FORCED_FLAG<<2)
#define FLAG_q (FORCED_FLAG<<3)
#define FLAG_v (FORCED_FLAG<<4)
#define FLAG_o (FORCED_FLAG<<5)
#define FLAG_a (FORCED_FLAG<<6)
#define FLAG_C (FORCED_FLAG<<7)
#define FLAG_R (FORCED_FLAG<<8)
#define FLAG_B (FORCED_FLAG<<9)
#define FLAG_S (FORCED_FLAG<<10)
#define FLAG_i (FORCED_FLAG<<11)
#define FLAG_p (FORCED_FLAG<<12)
#define FLAG_s (FORCED_FLAG<<13)
#define FLAG_t (FORCED_FLAG<<14)
#define FLAG_T (FORCED_FLAG<<15)
#define FLAG_A (FORCED_FLAG<<16)
#define FLAG_O (FORCED_FLAG<<17)
#define FLAG_r (FORCED_FLAG<<18)
#define FLAG_x (FORCED_FLAG<<19)
#define FLAG_F (FORCED_FLAG<<20)
#define FLAG_H (FORCED_FLAG<<21)
#define FLAG_V (FORCED_FLAG<<22)
#endif

// 修改后
#ifndef TT
#define TT this.dhcp
#endif
#define FLAG_f (1<<0)
#define FLAG_b (1<<1)
#define FLAG_n (1<<2)
#define FLAG_q (1<<3)
#define FLAG_v (1<<4)
#define FLAG_o (1<<5)
#define FLAG_a (1<<6)
#define FLAG_C (1<<7)
#define FLAG_R (1<<8)
#define FLAG_B (1<<9)
#define FLAG_S (1<<10)
#define FLAG_i (1<<11)
#define FLAG_p (1<<12)
#define FLAG_s (1<<13)
#define FLAG_t (1<<14)
#define FLAG_T (1<<15)
#define FLAG_A (1<<16)
#define FLAG_O (1<<17)
#define FLAG_r (1<<18)
#define FLAG_x (1<<19)
#define FLAG_F (1<<20)
#define FLAG_H (1<<21)
#define FLAG_V (1<<22)
#endif
  • 编译:
./build.sh --product-name Hi3516DV300 --ccache
  • 编译结束后重新烧写系统

脚本准备

  • 修改系统权限,目录能读能写:
mount -o remount,rw /
  • 发送脚本
    将default.script放入开发板/system/bin/的目录下,default.script见附件:
hdc_std.exe file send default.script /system/bin
  • 修改default.script的权限为可执行权限
chmod 0711 /system/bin/default.script

执行命令,进行动态IP获取。

ifconfig eth0 up
dhcp -i eth0 -s /system/bin/default.script

获取成功后,即可联网

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
default.rar 1013B 15次下载
已于2022-2-14 14:39:06修改
7
收藏 5
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐