S07bonding 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:
  4. # Short-Description: Network bonding support
  5. # Description: Enable bonding support as configured by user
  6. ### END INIT INFO
  7. . /opt/wz_mini/etc/rc.common
  8. . /opt/wz_mini/wz_mini.conf
  9. bonding_setup() {
  10. echo "#####$(basename "$0")#####"
  11. echo "waiting until wlan0 is up with the modified HWaddr"
  12. wait_for_wlan_wpa $(basename "$0")
  13. ##Fool iCamera by renaming the hardline interface to wlan0
  14. ## $1 Bonding Interface, $2 Primary Interface, $3 Secondary Interface
  15. echo "renaming interfaces"
  16. #Prevent iCamera from cycling the wlan0 interface
  17. mount --bind /opt/wz_mini/usr/bin/restart_wlan0.sh /system/bin/restart_wlan0.sh
  18. # Bring all interfaces down
  19. ifconfig bond0 down
  20. ifconfig $BONDING_PRIMARY_INTERFACE down
  21. ifconfig $BONDING_SECONDARY_INTERFACE down
  22. # Have to bring bonding interface up to be able to bond our slaves.
  23. /opt/wz_mini/bin/busybox ip link set bond0 up
  24. # Rename the real wlan0 interface if needed/used
  25. if [[ "$BONDING_PRIMARY_INTERFACE" == "wlan0" ]]; then
  26. /opt/wz_mini/bin/busybox ip link set $BONDING_PRIMARY_INTERFACE name wlanold
  27. /opt/wz_mini/bin/busybox ip addr flush dev wlanold
  28. BONDING_PRIMARY_INTERFACE="wlanold"
  29. # Because we just changed the name of the primary interface, we need to
  30. # tell the bonding driver about the name change as well.
  31. echo "$BONDING_PRIMARY_INTERFACE" > /sys/devices/virtual/net/bond0/bonding/primary
  32. fi
  33. if [[ "$BONDING_SECONDARY_INTERFACE" == "wlan0" ]]; then
  34. /opt/wz_mini/bin/busybox ip link set $BONDING_SECONDARY_INTERFACE name wlanold
  35. /opt/wz_mini/bin/busybox ip addr flush dev wlanold
  36. BONDING_SECONDARY_INTERFACE="wlanold"
  37. fi
  38. # Enslave the Ethernet and Original Wifi interfaces
  39. # under the bonding interface.
  40. /opt/wz_mini/tmp/.bin/ifenslave bond0 $BONDING_PRIMARY_INTERFACE $BONDING_SECONDARY_INTERFACE
  41. # Have to bring bonding interface down to be rename the interface
  42. /opt/wz_mini/bin/busybox ip link set bond0 down
  43. # Name the bonding interface to be the "new" wlan0 interface
  44. /opt/wz_mini/bin/busybox ip link set bond0 name wlan0
  45. # Bring the newly renamed wlan0 (actually the bond interface) back up in the next step
  46. #Run the DHCP client, and bind mount our fake wpa_cli.sh to fool iCamera
  47. ifconfig wlan0 up
  48. pkill udhcpc
  49. udhcpc -i wlan0 -x hostname:$CUSTOM_HOSTNAME -p /var/run/udhcpc.pid -b
  50. # If running with Interface Bonding enabled, kill any existing
  51. # wpa_supplicant that might be running and spawn our own instead
  52. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  53. echo "Restarting wpa_supplicant due to bonding"
  54. /opt/wz_mini/bin/busybox killall wpa_supplicant
  55. wpa_supplicant -D nl80211 -i wlanold -c /tmp/wpa_supplicant.conf -B -s
  56. fi
  57. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  58. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /system/bin/wpa_cli
  59. else
  60. mount -o bind /opt/wz_mini/bin/wpa_cli.sh /bin/wpa_cli
  61. fi
  62. echo "Run network monitor for USB Direct"
  63. /opt/wz_mini/usr/bin/netmon.sh &
  64. }
  65. case "$1" in
  66. start)
  67. if [[ "$BONDING_ENABLED" == "true" ]] && ([[ "$ENABLE_USB_ETH" == "true" ]] || [[ "$ENABLE_USB_DIRECT" == "true" ]]); then
  68. bonding_setup &
  69. fi
  70. ;;
  71. *)
  72. echo "Usage: $0 {start}"
  73. exit 1
  74. ;;
  75. esac