<file_sep>#!/bin/sh /etc/rc.common
#
#Start and Stop functions to run the ipkg package
#
PIDFILE_0=/var/run/wifi_dump_0.pid
PIDFILE_1=/var/run/wifi_dump_1.pid
HASH_KEY=/etc/bismark/passive.key
START=99

start(){
  
    if [ ! -f $HASH_KEY ]; then
        dd if=/dev/urandom of=$HASH_KEY bs=1 count=16 2>/dev/null
        echo "Generated fresh anonymization key"
    fi
    
    mkdir -p /tmp/bismark-uploads/mac-analyzer
    mkdir -p /tmp/mac-analyzer
    
    
    iw phy phy0 interface add phe0 type monitor flags fcsfail control otherbss 2>/dev/null
    p0=$?
    if [ "$p0" -eq "0" ];then
        mon0='phe0'
        echo "phe0 created  "
    else
        echo "Err: can't creat phe0"
        exit 1
    fi
    
    ifconfig $mon0 up 
    p0=$?
    if [ "$p0" -eq "0" ];then
        echo "radio 0 interface  up"
    else
        echo "Err: can't turn radio 0 interface  up"
        exit 1
    fi    

    iw phy phy1 interface add phe1 type monitor flags fcsfail control otherbss 2>/dev/null
    p1=$?
    if [ "$p1" -eq "0" ];then
        mon1='phe1'    
        echo "phe1 created  " 
    else
        echo "Err: can't creat phe1"
        exit 1
    fi

    ifconfig $mon1 up 
    p1=$?
    if [ "$p1" -eq "0" ];then
        echo "radio 0 interface  up"
    else
        echo "Err: can't turn radio 0 interface  up"
        exit 1
    fi

#check the argument
    if [ -f $PIDFILE_0 ]; then
        echo "pidfile $PIDFILE_0 already exists; mac analyzer already running"
        exit 1
    fi
    
    if [ -f $PIDFILE_1 ]; then
        echo "pidfile $PIDFILE_1 already exists; mac analyzer already running"
        exit 1
    fi
    
    start-stop-daemon -S \
    -x /tmp/usr/bin/wifi_dump \
    -p $PIDFILE_0 \
    -m -b $mon0
    
    echo "installed on phe0 interface; now running phe1 interface"
    sleep 3
    start-stop-daemon -S \
  -x /tmp/usr/bin/wifi_dump \
  -p $PIDFILE_1 \
  -m -b $mon1
}


stop(){
    
    [ -f $PIDFILE_0 ] && {
  start-stop-daemon -K -q -p $PIDFILE_0 -s TERM
  rm -f $PIDFILE_0

    }
    [ -f $PIDFILE_1 ] && {
  start-stop-daemon -K -q -p $PIDFILE_1 -s TERM
  rm -f $PIDFILE_1

    }
#    ifconfig phe0 down 
#    p1=$?
#    if [ "$p1" -eq "0" ];then
#        echo "phe0 turned down"
#    fi
    
#    ifconfig phe1 down 
#    p1=$?
#    if [ "$p1" -eq "0" ];then
#        echo "phe1 turned down"
#    fi

    iw dev phe0 del 2>/dev/null
    p1=$?
    if [ "$p1" -eq "0" ];then
        echo "deleted phe0 interface "
    fi

    iw dev phe1 del 2>/dev/null
    p1=$?
    if [ "$p1" -eq "0" ];then
        echo "deleted phe1 interface "
    fi
    
}

restart(){
    stop
    start
}
<file_sep># Copyright (C) 2006-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=wifi-dump-tmpfs
PKG_RELEASE:=12
PKG_VERSION:=HEAD

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=git://github.com/abnarain/wifi_dump-tmpfs.git
PKG_SOURCE_VERSION:=$(PKG_VERSION)
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_PROTO:=git
#GIT_URL:=git:/
#GIT_URL:=src/

include $(INCLUDE_DIR)/package.mk

define Package/wifi-dump-tmpfs
	SECTION:=net
	CATEGORY:=Network
	TITLE:=BISmark Wireless Measurements tool 
	URL:=http://doesnotexist.com
	DEPENDS:=+zlib +bismark-data-transmit 
endef

define Package/bismark-active-tmpfs/description
 This tool collects wireless traces in monitor mode. This tool is a part of infrastructure to understand wireless home networks.
endef

define Package/wifi-dump-tmpfs/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifi_dump $(1)/usr/bin/wifi_dump.bin
	$(INSTALL_BIN) ./files/etc/init.d/wifi_dump $(1)/etc/init.d/wifi_dump
	$(INSTALL_BIN) ./files/usr/bin/wifi_dump $(1)/usr/bin/wifi_dump
endef

 
define Package/wifi-dump-tmpfs/postinst
#!/bin/sh
#killall wifi_dump
#rm /var/run/wifi_dump.pid
start-stop-daemon -K -q -p /var/run/wifi_dump.pid -s TERM
/tmp/etc/init.d/wifi_dump restart
endef

define Package/wifi-dump-tmpfs/prerm
#!/bin/sh
/tmp/etc/init.d/wifi_dump stop
endef

$(eval $(call BuildPackage,wifi-dump-tmpfs))
