From f0336c7de553c46d182f4007525fcce828b8da8f Mon Sep 17 00:00:00 2001 From: suyuan <175338101@qq.com> Date: Fri, 24 Nov 2023 14:44:51 +0800 Subject: [PATCH] fix modemmanager --- modemmanager/Makefile | 9 +- modemmanager/README.md | 4 - modemmanager/files/10-report-down | 11 +- modemmanager/files/modemmanager.common | 2 +- modemmanager/files/modemmanager.init | 4 - modemmanager/files/modemmanager.proto | 113 ++++-------------- .../files/usr/sbin/ModemManager-wrapper | 2 - 7 files changed, 35 insertions(+), 110 deletions(-) mode change 100755 => 100644 modemmanager/files/10-report-down mode change 100755 => 100644 modemmanager/files/modemmanager.init mode change 100755 => 100644 modemmanager/files/modemmanager.proto mode change 100644 => 100755 modemmanager/files/usr/sbin/ModemManager-wrapper diff --git a/modemmanager/Makefile b/modemmanager/Makefile index e484b7fbd..d30b1a2e9 100644 --- a/modemmanager/Makefile +++ b/modemmanager/Makefile @@ -64,7 +64,6 @@ MESON_ARGS += \ -Dintrospection=false \ -Dman=false \ -Dbash_completion=false \ - -Dbuiltin_plugins=true \ -Db_lto=true \ -Dmbim=$(if $(CONFIG_MODEMMANAGER_WITH_MBIM),true,false) \ -Dqmi=$(if $(CONFIG_MODEMMANAGER_WITH_QMI),true,false) \ @@ -81,8 +80,6 @@ define Build/InstallDev $(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/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 define Package/modemmanager/install @@ -99,6 +96,10 @@ define Package/modemmanager/install $(INSTALL_DIR) $(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_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_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_DIR) $(1)/usr/share/ModemManager/fcc-unlock.available.d diff --git a/modemmanager/README.md b/modemmanager/README.md index 93a7f9b09..c9d880ea4 100644 --- a/modemmanager/README.md +++ b/modemmanager/README.md @@ -22,10 +22,8 @@ Once installed, you can configure the 2G/3G/4G modem connections directly in option password 'vodafone' option pincode '7423' option iptype 'ipv4' - option plmn '214001' option lowpower '1' option signalrate '30' - option allow_roaming '1' Only 'device' and 'proto' are mandatory options, the remaining ones are all optional. @@ -38,7 +36,5 @@ allowing all protocols. The 'iptype' option supports any of these values: 'ipv4', 'ipv6' or 'ipv4v6'. 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. You can call signal info with command: mmcli -m 0 --signal-get diff --git a/modemmanager/files/10-report-down b/modemmanager/files/10-report-down old mode 100755 new mode 100644 index 88b010cf0..a3e5fb4ba --- a/modemmanager/files/10-report-down +++ b/modemmanager/files/10-report-down @@ -29,12 +29,7 @@ MODEM_DEVICE=$(modemmanager_get_field "${MODEM_STATUS}" "modem.generic.device") CFG=$(mm_get_modem_config "${MODEM_DEVICE}") [ -n "${CFG}" ] || exit 3 -IFUP=$(ifstatus "${CFG}" | jsonfilter -e "@.up") - -[ "${IFUP}" = "true" ] && { - logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}" - proto_init_update $INTERFACE 0 - proto_send_update $CFG -} - +logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}" +proto_init_update $INTERFACE 0 +proto_send_update $CFG exit 0 diff --git a/modemmanager/files/modemmanager.common b/modemmanager/files/modemmanager.common index 2ba2036ce..e47e0e025 100644 --- a/modemmanager/files/modemmanager.common +++ b/modemmanager/files/modemmanager.common @@ -22,7 +22,7 @@ MODEMMANAGER_EVENTS_CACHE="${MODEMMANAGER_RUNDIR}/events.cache" mm_log() { 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: $*" } ################################################################################ diff --git a/modemmanager/files/modemmanager.init b/modemmanager/files/modemmanager.init old mode 100755 new mode 100644 index a036d884d..c19022031 --- a/modemmanager/files/modemmanager.init +++ b/modemmanager/files/modemmanager.init @@ -4,8 +4,6 @@ USE_PROCD=1 START=70 -LOG_LEVEL="INFO" - start_service() { # Setup ModemManager service # @@ -23,8 +21,6 @@ start_service() { . /usr/share/ModemManager/modemmanager.common procd_open_instance 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 pidfile "${MODEMMANAGER_PID_FILE}" procd_close_instance diff --git a/modemmanager/files/modemmanager.proto b/modemmanager/files/modemmanager.proto old mode 100755 new mode 100644 index a4d837c1e..b8ebce924 --- a/modemmanager/files/modemmanager.proto +++ b/modemmanager/files/modemmanager.proto @@ -323,20 +323,28 @@ modemmanager_connected_method_static_ipv6() { 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() { available=1 no_device=1 - proto_config_add_string device - proto_config_add_string apn - proto_config_add_string 'allowedauth:list(string)' - proto_config_add_string username - proto_config_add_string password - proto_config_add_string allowedmode - proto_config_add_string preferredmode - proto_config_add_string pincode - proto_config_add_string iptype - proto_config_add_string plmn - proto_config_add_int signalrate + proto_config_add_string device + proto_config_add_string apn + proto_config_add_string 'allowedauth:list(string)' + proto_config_add_string username + proto_config_add_string password + proto_config_add_string pincode + proto_config_add_string iptype + proto_config_add_string plmn + proto_config_add_int signalrate proto_config_add_boolean lowpower proto_config_add_boolean allow_roaming proto_config_add_defaults @@ -351,65 +359,18 @@ append_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() { local interface="$1" local modempath modemstatus bearercount bearerpath connectargs bearerstatus beareriface local bearermethod_ipv4 bearermethod_ipv6 auth cliauth local operatorname operatorid registration accesstech signalquality - local allowedmode preferredmode - local device apn allowedauth username password pincode - local iptype plmn metric signalrate allow_roaming + local device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming local address prefix gateway mtu dns1 dns2 - json_get_vars device apn allowedauth username password - json_get_vars pincode iptype plmn metric signalrate allow_roaming - json_get_vars allowedmode preferredmode + json_get_vars device apn allowedauth username password pincode iptype plmn metric signalrate allow_roaming # validate sysfs path given in config [ -n "${device}" ] || { @@ -430,33 +391,6 @@ proto_modemmanager_setup() { } 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 modemmanager_cleanup_connection "${modemstatus}" @@ -619,6 +553,7 @@ proto_modemmanager_teardown() { # disconnection handling only requires special treatment in IPv4/PPP [ "${bearermethod_ipv4}" = "ppp" ] && modemmanager_disconnected_method_ppp_ipv4 "${interface}" + modemmanager_disconnected_method_common "${interface}" # disconnect mmcli --modem="${device}" --simple-disconnect || @@ -626,10 +561,14 @@ proto_modemmanager_teardown() { # disable mmcli --modem="${device}" --disable + proto_notify_error "${interface}" MM_MODEM_DISABLED # low power, only if requested [ "${lowpower:-0}" -lt 1 ] || mmcli --modem="${device}" --set-power-state-low + + proto_init_update "*" 0 + proto_send_update "$interface" } [ -n "$INCLUDE_ONLY" ] || { diff --git a/modemmanager/files/usr/sbin/ModemManager-wrapper b/modemmanager/files/usr/sbin/ModemManager-wrapper old mode 100644 new mode 100755 index 97c2a826d..e06d943e9 --- a/modemmanager/files/usr/sbin/ModemManager-wrapper +++ b/modemmanager/files/usr/sbin/ModemManager-wrapper @@ -27,8 +27,6 @@ main() { mm_report_events_from_cache wait "$CHILD" - - # Set all configured interfaces as unavailable mm_cleanup_interfaces }