1453df54542b1f597b30d4f7ded66c6b161b0bc5cPaul Stewart#!/bin/sh
2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#
3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# Copyright (C) 2011 The Android Open Source Project
4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#
5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# Licensed under the Apache License, Version 2.0 (the "License");
6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# you may not use this file except in compliance with the License.
7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# You may obtain a copy of the License at
8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#
9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#      http://www.apache.org/licenses/LICENSE-2.0
10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#
11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# Unless required by applicable law or agreed to in writing, software
12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# distributed under the License is distributed on an "AS IS" BASIS,
13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# See the License for the specific language governing permissions and
15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu# limitations under the License.
16c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu#
172a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov#
182a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov# Set the ARP gateway.
192a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
202a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin PetkovFLAGS_HELP="Usage:
212a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
222a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  $(basename $0)
232a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
242a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovor
252a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
262a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  $(basename $0) [true | false]
272a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov"
282a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
292a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin PetkovFLIMFLAM=org.chromium.flimflam
302a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin PetkovIMANAGER=$FLIMFLAM.Manager
312a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
322a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovusage() {
33453df54542b1f597b30d4f7ded66c6b161b0bc5cPaul Stewart  echo "$*"
342a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  echo
352a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  echo $FLAGS_HELP
362a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  exit 1
372a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov}
382a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
392a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovdbus () {
402a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  local obj=$1
412a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  local meth=$2
422a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  shift 2
432a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
442a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  dbus-send --system --print-reply --fixed --dest=$FLIMFLAM "$obj" "$meth" "$@"
452a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov}
462a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
472a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovget_manager () {
482a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  dbus / $IMANAGER.GetProperties | sed -n "/$1/s/.* //p"
492a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov}
502a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
512a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovdisplay_arpgw () {
522a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  local arpgw=$(get_manager ArpGateway)
532a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
542a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  if [ -n "$arpgw" ] ; then
552a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov    echo "Current Gateway ARP setting: " $arpgw
562a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov    exit 0
572a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  fi
582a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
592a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  echo "This Flimflam instance does not support ArpGateway"
602a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov  exit 0
612a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov}
622a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
632a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovif [ $# -lt 1 ]; then
642a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov    display_arpgw
652a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovfi
662a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
672a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovset_arpgw=$1
682a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
692a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovif [ $set_arpgw != false -a $set_arpgw != true ] ; then
702a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov    usage "Argument must be 'true' or 'false'"
712a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovfi
722a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkov
732a0614ea9d6d6406f8647a0d8dc4ed4c47cbb222Darin Petkovdbus / $IMANAGER.SetProperty string:"ArpGateway" variant:boolean:$set_arpgw
74