1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

fix modemmanager

This commit is contained in:
suyuan 2023-11-24 14:44:51 +08:00
parent 36efe9515d
commit f0336c7de5
7 changed files with 35 additions and 110 deletions

View file

@ -64,7 +64,6 @@ MESON_ARGS += \
-Dintrospection=false \ -Dintrospection=false \
-Dman=false \ -Dman=false \
-Dbash_completion=false \ -Dbash_completion=false \
-Dbuiltin_plugins=true \
-Db_lto=true \ -Db_lto=true \
-Dmbim=$(if $(CONFIG_MODEMMANAGER_WITH_MBIM),true,false) \ -Dmbim=$(if $(CONFIG_MODEMMANAGER_WITH_MBIM),true,false) \
-Dqmi=$(if $(CONFIG_MODEMMANAGER_WITH_QMI),true,false) \ -Dqmi=$(if $(CONFIG_MODEMMANAGER_WITH_QMI),true,false) \
@ -81,8 +80,6 @@ define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/ModemManager.pc $(1)/usr/lib/pkgconfig $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/ModemManager.pc $(1)/usr/lib/pkgconfig
$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/mm-glib.pc $(1)/usr/lib/pkgconfig $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/mm-glib.pc $(1)/usr/lib/pkgconfig
$(INSTALL_DIR) $(1)/usr/share/dbus-1/interfaces
$(CP) $(PKG_BUILD_DIR)/introspection/org.freedesktop.ModemManager1.* $(1)/usr/share/dbus-1/interfaces
endef endef
define Package/modemmanager/install define Package/modemmanager/install
@ -99,6 +96,10 @@ define Package/modemmanager/install
$(INSTALL_DIR) $(1)/usr/lib $(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libmm-glib.so.* $(1)/usr/lib $(CP) $(PKG_INSTALL_DIR)/usr/lib/libmm-glib.so.* $(1)/usr/lib
$(INSTALL_DIR) $(1)/usr/lib/ModemManager
$(CP) $(PKG_INSTALL_DIR)/usr/lib/ModemManager/libmm-shared-*.so* $(1)/usr/lib/ModemManager
$(CP) $(PKG_INSTALL_DIR)/usr/lib/ModemManager/libmm-plugin-*.so* $(1)/usr/lib/ModemManager
$(INSTALL_DIR) $(1)/usr/lib/ModemManager/connection.d $(INSTALL_DIR) $(1)/usr/lib/ModemManager/connection.d
$(INSTALL_BIN) ./files/10-report-down $(1)/usr/lib/ModemManager/connection.d $(INSTALL_BIN) ./files/10-report-down $(1)/usr/lib/ModemManager/connection.d
@ -109,7 +110,7 @@ define Package/modemmanager/install
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service $(1)/usr/share/dbus-1/system-services $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service $(1)/usr/share/dbus-1/system-services
$(INSTALL_DIR) $(1)/usr/share/ModemManager $(INSTALL_DIR) $(1)/usr/share/ModemManager
$$(if $$(wildcard $(PKG_INSTALL_DIR)/usr/share/ModemManager/*.conf),$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/ModemManager/*.conf $(1)/usr/share/ModemManager,) $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/ModemManager/*.conf $(1)/usr/share/ModemManager
$(INSTALL_DATA) ./files/modemmanager.common $(1)/usr/share/ModemManager $(INSTALL_DATA) ./files/modemmanager.common $(1)/usr/share/ModemManager
$(INSTALL_DIR) $(1)/usr/share/ModemManager/fcc-unlock.available.d $(INSTALL_DIR) $(1)/usr/share/ModemManager/fcc-unlock.available.d

View file

@ -22,10 +22,8 @@ Once installed, you can configure the 2G/3G/4G modem connections directly in
option password 'vodafone' option password 'vodafone'
option pincode '7423' option pincode '7423'
option iptype 'ipv4' option iptype 'ipv4'
option plmn '214001'
option lowpower '1' option lowpower '1'
option signalrate '30' option signalrate '30'
option allow_roaming '1'
Only 'device' and 'proto' are mandatory options, the remaining ones are all Only 'device' and 'proto' are mandatory options, the remaining ones are all
optional. optional.
@ -38,7 +36,5 @@ allowing all protocols.
The 'iptype' option supports any of these values: 'ipv4', 'ipv6' or 'ipv4v6'. The 'iptype' option supports any of these values: 'ipv4', 'ipv6' or 'ipv4v6'.
It will default to 'ipv4' if not given. It will default to 'ipv4' if not given.
The 'plmn' option allows to set the network operator MCCMNC.
The 'signalrate' option set's the signal refresh rate (in seconds) for the device. The 'signalrate' option set's the signal refresh rate (in seconds) for the device.
You can call signal info with command: mmcli -m 0 --signal-get You can call signal info with command: mmcli -m 0 --signal-get

11
modemmanager/files/10-report-down Executable file → Normal file
View file

@ -29,12 +29,7 @@ MODEM_DEVICE=$(modemmanager_get_field "${MODEM_STATUS}" "modem.generic.device")
CFG=$(mm_get_modem_config "${MODEM_DEVICE}") CFG=$(mm_get_modem_config "${MODEM_DEVICE}")
[ -n "${CFG}" ] || exit 3 [ -n "${CFG}" ] || exit 3
IFUP=$(ifstatus "${CFG}" | jsonfilter -e "@.up") logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}"
proto_init_update $INTERFACE 0
[ "${IFUP}" = "true" ] && { proto_send_update $CFG
logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}"
proto_init_update $INTERFACE 0
proto_send_update $CFG
}
exit 0 exit 0

View file

@ -22,7 +22,7 @@ MODEMMANAGER_EVENTS_CACHE="${MODEMMANAGER_RUNDIR}/events.cache"
mm_log() { mm_log() {
local level="$1"; shift local level="$1"; shift
logger -p "daemon.${level}" -t "ModemManager[$$]" "hotplug: $*" [ "$(uci -q get openmptcprouter.settings.debug)" = "true" ] && logger -p "daemon.${level}" -t "ModemManager[$$]" "hotplug: $*"
} }
################################################################################ ################################################################################

4
modemmanager/files/modemmanager.init Executable file → Normal file
View file

@ -4,8 +4,6 @@
USE_PROCD=1 USE_PROCD=1
START=70 START=70
LOG_LEVEL="INFO"
start_service() { start_service() {
# Setup ModemManager service # Setup ModemManager service
# #
@ -23,8 +21,6 @@ start_service() {
. /usr/share/ModemManager/modemmanager.common . /usr/share/ModemManager/modemmanager.common
procd_open_instance procd_open_instance
procd_set_param command /usr/sbin/ModemManager-wrapper procd_set_param command /usr/sbin/ModemManager-wrapper
procd_append_param command --log-level="$LOG_LEVEL"
[ "$LOG_LEVEL" = "DEBUG" ] && procd_append_param command --debug
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param pidfile "${MODEMMANAGER_PID_FILE}" procd_set_param pidfile "${MODEMMANAGER_PID_FILE}"
procd_close_instance procd_close_instance

113
modemmanager/files/modemmanager.proto Executable file → Normal file
View file

@ -323,20 +323,28 @@ modemmanager_connected_method_static_ipv6() {
proto_send_update "${interface}" proto_send_update "${interface}"
} }
modemmanager_disconnected_method_common() {
local interface="$1"
echo "running disconnection (common)"
proto_notify_error "${interface}" MM_DISCONNECT_IN_PROGRESS
proto_init_update "*" 0
proto_send_update "${interface}"
}
proto_modemmanager_init_config() { proto_modemmanager_init_config() {
available=1 available=1
no_device=1 no_device=1
proto_config_add_string device proto_config_add_string device
proto_config_add_string apn proto_config_add_string apn
proto_config_add_string 'allowedauth:list(string)' proto_config_add_string 'allowedauth:list(string)'
proto_config_add_string username proto_config_add_string username
proto_config_add_string password proto_config_add_string password
proto_config_add_string allowedmode proto_config_add_string pincode
proto_config_add_string preferredmode proto_config_add_string iptype
proto_config_add_string pincode proto_config_add_string plmn
proto_config_add_string iptype proto_config_add_int signalrate
proto_config_add_string plmn
proto_config_add_int signalrate
proto_config_add_boolean lowpower proto_config_add_boolean lowpower
proto_config_add_boolean allow_roaming proto_config_add_boolean allow_roaming
proto_config_add_defaults proto_config_add_defaults
@ -351,65 +359,18 @@ append_param() {
connectargs="${connectargs}${param}" connectargs="${connectargs}${param}"
} }
modemmanager_set_allowed_mode() {
local device="$1"
local interface="$2"
local allowedmode="$3"
echo "setting allowed mode to '${allowedmode}'"
mmcli --modem="${device}" --set-allowed-modes="${allowedmode}" || {
proto_notify_error "${interface}" MM_INVALID_ALLOWED_MODES_LIST
proto_block_restart "${interface}"
return 1
}
}
modemmanager_set_preferred_mode() {
local device="$1"
local interface="$2"
local allowedmode="$3"
local preferredmode="$4"
[ -z "${preferredmode}" ] && {
echo "no preferred mode configured"
proto_notify_error "${interface}" MM_NO_PREFERRED_MODE_CONFIGURED
proto_block_restart "${interface}"
return 1
}
[ -z "${allowedmode}" ] && {
echo "no allowed mode configured"
proto_notify_error "${interface}" MM_NO_ALLOWED_MODE_CONFIGURED
proto_block_restart "${interface}"
return 1
}
echo "setting preferred mode to '${preferredmode}' (${allowedmode})"
mmcli --modem="${device}" \
--set-preferred-mode="${preferredmode}" \
--set-allowed-modes="${allowedmode}" || {
proto_notify_error "${interface}" MM_FAILED_SETTING_PREFERRED_MODE
proto_block_restart "${interface}"
return 1
}
}
proto_modemmanager_setup() { proto_modemmanager_setup() {
local interface="$1" local interface="$1"
local modempath modemstatus bearercount bearerpath connectargs bearerstatus beareriface local modempath modemstatus bearercount bearerpath connectargs bearerstatus beareriface
local bearermethod_ipv4 bearermethod_ipv6 auth cliauth local bearermethod_ipv4 bearermethod_ipv6 auth cliauth
local operatorname operatorid registration accesstech signalquality local operatorname operatorid registration accesstech signalquality
local allowedmode preferredmode
local device apn allowedauth username password pincode local device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming
local iptype plmn metric signalrate allow_roaming
local address prefix gateway mtu dns1 dns2 local address prefix gateway mtu dns1 dns2
json_get_vars device apn allowedauth username password json_get_vars device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming
json_get_vars pincode iptype plmn metric signalrate allow_roaming
json_get_vars allowedmode preferredmode
# validate sysfs path given in config # validate sysfs path given in config
[ -n "${device}" ] || { [ -n "${device}" ] || {
@ -430,33 +391,6 @@ proto_modemmanager_setup() {
} }
echo "modem available at ${modempath}" echo "modem available at ${modempath}"
[ -z "${allowedmode}" ] || {
case "$allowedmode" in
"2g")
modemmanager_set_allowed_mode "$device" \
"$interface" "2g"
;;
"3g")
modemmanager_set_allowed_mode "$device" \
"$interface" "3g"
;;
"4g")
modemmanager_set_allowed_mode "$device" \
"$interface" "4g"
;;
"5g")
modemmanager_set_allowed_mode "$device" \
"$interface" "5g"
;;
*)
modemmanager_set_preferred_mode "$device" \
"$interface" "${allowedmode}" "${preferredmode}"
;;
esac
# check error for allowed_mode and preferred_mode function call
[ "$?" -ne "0" ] && return 1
}
# always cleanup before attempting a new connection, just in case # always cleanup before attempting a new connection, just in case
modemmanager_cleanup_connection "${modemstatus}" modemmanager_cleanup_connection "${modemstatus}"
@ -619,6 +553,7 @@ proto_modemmanager_teardown() {
# disconnection handling only requires special treatment in IPv4/PPP # disconnection handling only requires special treatment in IPv4/PPP
[ "${bearermethod_ipv4}" = "ppp" ] && modemmanager_disconnected_method_ppp_ipv4 "${interface}" [ "${bearermethod_ipv4}" = "ppp" ] && modemmanager_disconnected_method_ppp_ipv4 "${interface}"
modemmanager_disconnected_method_common "${interface}"
# disconnect # disconnect
mmcli --modem="${device}" --simple-disconnect || mmcli --modem="${device}" --simple-disconnect ||
@ -626,10 +561,14 @@ proto_modemmanager_teardown() {
# disable # disable
mmcli --modem="${device}" --disable mmcli --modem="${device}" --disable
proto_notify_error "${interface}" MM_MODEM_DISABLED
# low power, only if requested # low power, only if requested
[ "${lowpower:-0}" -lt 1 ] || [ "${lowpower:-0}" -lt 1 ] ||
mmcli --modem="${device}" --set-power-state-low mmcli --modem="${device}" --set-power-state-low
proto_init_update "*" 0
proto_send_update "$interface"
} }
[ -n "$INCLUDE_ONLY" ] || { [ -n "$INCLUDE_ONLY" ] || {

2
modemmanager/files/usr/sbin/ModemManager-wrapper Normal file → Executable file
View file

@ -27,8 +27,6 @@ main() {
mm_report_events_from_cache mm_report_events_from_cache
wait "$CHILD" wait "$CHILD"
# Set all configured interfaces as unavailable
mm_cleanup_interfaces mm_cleanup_interfaces
} }