p2p scripts: generalize support getting name from configuration

The P2P interface may have a different name, for instance, in the ccimx93 it
is wfd (wifi direct).
Generalize Digi P2P scripts to use the name from the platform config file.

https://onedigi.atlassian.net/browse/DEL-8468

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2023-08-29 12:58:09 +02:00
parent 3641b93750
commit eba8e21d72
4 changed files with 16 additions and 12 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright 2019, Digi International Inc. # Copyright 2019-2023, Digi International Inc.
# #
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
@ -18,9 +18,11 @@
# #
# This script is specific to create a P2P (BATMAN) bridge, so # This script is specific to create a P2P (BATMAN) bridge, so
# require the CONNECTION_ID to be "p2p-bridge" # requires the CONNECTION_ID to be "p2p-bridge"
[ "${CONNECTION_ID}" = "p2p-bridge" ] || exit 0 [ "${CONNECTION_ID}" = "p2p-bridge" ] || exit 0
P2P_IFACE="##WLAN_P2P_INTERFACE##"
log() { log() {
if type "systemd-cat" >/dev/null 2>/dev/null; then if type "systemd-cat" >/dev/null 2>/dev/null; then
systemd-cat -p "${1}" -t p2pbridge printf "%s" "${2}" systemd-cat -p "${1}" -t p2pbridge printf "%s" "${2}"
@ -32,13 +34,13 @@ log() {
case "${NM_DISPATCHER_ACTION}" in case "${NM_DISPATCHER_ACTION}" in
pre-up) pre-up)
# Reset virtual interfaces # Reset virtual interfaces
{ batctl if destroy; ifdown -f p2p0; } >/dev/null 2>&1 { batctl if destroy; ifdown -f "${P2P_IFACE}"; } >/dev/null 2>&1
# Bring P2P link up # Bring P2P link up
log info "bring P2P link UP" log info "bring P2P link UP"
ifup p2p0 || { log err "p2p link NOT created"; exit 1; } ifup "${P2P_IFACE}" || { log err "p2p link NOT created"; exit 1; }
for P2P_IFNAME in $(basename $(echo /sys/class/net/p2p-p2p0-*)); do for P2P_IFNAME in $(basename $(echo /sys/class/net/p2p-"${P2P_IFACE}"-*)); do
echo "${P2P_IFNAME}" | grep -qs 'p2p-p2p0-\*' && continue echo "${P2P_IFNAME}" | grep -qs "p2p-${P2P_IFACE}-\*" && continue
ifconfig "${P2P_IFNAME}" 0.0.0.0 ifconfig "${P2P_IFNAME}" 0.0.0.0
p2p_iface_found="1" p2p_iface_found="1"
break break
@ -61,7 +63,7 @@ down)
batctl if destroy batctl if destroy
log info "bring P2P link DOWN" log info "bring P2P link DOWN"
ifdown -f p2p0 || { log err "unable to bring P2P link DOWN"; exit 1; } ifdown -f "${P2P_IFACE}" || { log err "unable to bring P2P link DOWN"; exit 1; }
;; ;;
*) *)
# Do nothing # Do nothing

View File

@ -104,6 +104,7 @@ do_install:append() {
install -m 0755 ${WORKDIR}/01dispatcher ${D}${sysconfdir}/NetworkManager/dispatcher.d/ install -m 0755 ${WORKDIR}/01dispatcher ${D}${sysconfdir}/NetworkManager/dispatcher.d/
install -m 0755 ${WORKDIR}/ifdownup ${D}${sysconfdir}/NetworkManager/dispatcher.d/device-connectivity-change.d/ install -m 0755 ${WORKDIR}/ifdownup ${D}${sysconfdir}/NetworkManager/dispatcher.d/device-connectivity-change.d/
install -m 0755 ${WORKDIR}/p2pbridge ${D}${sysconfdir}/NetworkManager/dispatcher.d/pre-up.d/ install -m 0755 ${WORKDIR}/p2pbridge ${D}${sysconfdir}/NetworkManager/dispatcher.d/pre-up.d/
sed -i -e 's,##WLAN_P2P_INTERFACE##,${WLAN_P2P_INTERFACE},g' ${D}${sysconfdir}/NetworkManager/dispatcher.d/pre-up.d/p2pbridge
ln -s ../pre-up.d/p2pbridge ${D}${sysconfdir}/NetworkManager/dispatcher.d/down.d/p2pbridge ln -s ../pre-up.d/p2pbridge ${D}${sysconfdir}/NetworkManager/dispatcher.d/down.d/p2pbridge
# Disable terminal colors by default # Disable terminal colors by default

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright 2019, Digi International Inc. # Copyright 2019-2023, Digi International Inc.
# #
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
@ -27,8 +27,8 @@
# p2p-network-id <wpa_supplicant_conf P2P network ID> # p2p-network-id <wpa_supplicant_conf P2P network ID>
# #
# Execute only for the p2p0 interface # Execute only for the P2P interface
[ "${IFACE}" = "p2p0" ] || exit 0 [ "${IFACE}" = "##WLAN_P2P_INTERFACE##" ] || exit 0
log() { log() {
if type "systemd-cat" >/dev/null 2>/dev/null; then if type "systemd-cat" >/dev/null 2>/dev/null; then
@ -68,8 +68,8 @@ if [ "${MODE}" = "start" ]; then
if [ -n "${p2p_link_found}" ]; then if [ -n "${p2p_link_found}" ]; then
# Configure the newly created interface # Configure the newly created interface
if [ -n "${IF_P2P_LOCAL_ADDRESS}" ]; then if [ -n "${IF_P2P_LOCAL_ADDRESS}" ]; then
for P2P_IFNAME in $(basename $(echo /sys/class/net/p2p-p2p0-*)); do for P2P_IFNAME in $(basename $(echo /sys/class/net/p2p-"${IFACE}"-*)); do
echo "${P2P_IFNAME}" | grep -qs 'p2p-p2p0-\*' && continue echo "${P2P_IFNAME}" | grep -qs "p2p-${IFACE}-\*" && continue
ifconfig "${P2P_IFNAME}" "${IF_P2P_LOCAL_ADDRESS}" ${IF_P2P_LOCAL_NETMASK:+netmask ${IF_P2P_LOCAL_NETMASK}} up ifconfig "${P2P_IFNAME}" "${IF_P2P_LOCAL_ADDRESS}" ${IF_P2P_LOCAL_NETMASK:+netmask ${IF_P2P_LOCAL_NETMASK}} up
break break
done done

View File

@ -47,6 +47,7 @@ do_install:append() {
cat ${WORKDIR}/interfaces.p2p >> ${D}${sysconfdir}/network/interfaces cat ${WORKDIR}/interfaces.p2p >> ${D}${sysconfdir}/network/interfaces
[ -n "${WLAN_P2P_AUTO}" ] && sed -i -e 's/^#auto ##WLAN_P2P_INTERFACE##/auto ##WLAN_P2P_INTERFACE##/g' ${D}${sysconfdir}/network/interfaces [ -n "${WLAN_P2P_AUTO}" ] && sed -i -e 's/^#auto ##WLAN_P2P_INTERFACE##/auto ##WLAN_P2P_INTERFACE##/g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##WLAN_P2P_INTERFACE##,${WLAN_P2P_INTERFACE},g' ${D}${sysconfdir}/network/interfaces sed -i -e 's,##WLAN_P2P_INTERFACE##,${WLAN_P2P_INTERFACE},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##WLAN_P2P_INTERFACE##,${WLAN_P2P_INTERFACE},g' ${D}${sysconfdir}/network/if-up.d/p2plink
fi fi
fi fi