[Q] HowTethering A101 firm 2.3.81 with BackBerry 9800 ? - Gen8, Gen9, Gen10 Q&A, Help & Troubleshooting

Hello, in other forum, " dervari " resolved the tethering A101 with BlackBerry:
in /system/etc/ppp/peers/tether, change novj for #novj
in /system/bin/tether_start_dun.sh., change if [$# -eq 4 ] for if [ $# -eq 4 ]
but that was with firmware 2.3.26... now, the new firmware 2.3.81 changed these scripts..
my questions:
.- This changes makes tethering A101 with BlackBerry ?
.- Not necesary makes more changes in scripts ?
new /system/etc/ppp/peers/tether in 2.3.81:
#debug
# connection
crtscts
hide-password
nodetach
# peer parameters
noauth
# most gprs phones don't reply to lcp echo
lcp-echo-interval 0
lcp-echo-failure 0
# dns, routing
ipcp-accept-remote
ipcp-accept-local
defaultroute
#replacedefaultroute # not currently supported by our pppd
noipdefault
usepeerdns
# avoid compression
# novj is now an option
novjccomp
noccp
nobsdcomp
nopcomp
noaccomp
# connect scripts
connect '/system/xbin/chat -v -t3 -f /data/tether_start'
disconnect '/system/xbin/chat -v -t3 -f /etc/chatscripts/tether_stop'
new /system/bin/tether_start_dun.sh in 2.3.81:
#!/bin/sh
# $1 is the mac address of the phone
# $2 is the channel
# $3 is the user (not a mandatory argument)
# $4 is the password (not a mandatory argument)
# $5 is the novj option
MAC=$1
CHANNEL=$2
USER=$3
PWD=$4
NOVJ=$5
if [ "$USER" = "" ]
then
/system/xbin/dund --connect $MAC --channel $CHANNEL --pppd /system/bin/pppd /dev/rfcomm0 115200 mru 1280 mtu 1280 $NOVJ call tether
else
/system/xbin/dund --connect $MAC --channel $CHANNEL --pppd /system/bin/pppd /dev/rfcomm0 115200 mru 1280 mtu 1280 $NOVJ name $USER password $PWD call tether
fi

Related

[howto][script] peek at DNS queries

Here's a script I use to track all DNS queries any Android app is doing.
It will show which hostnames some app is about to contact for resources, including, but not limited to adverts, updates, rogue hosts, thumbnail images, news sources etc.
Prerequisites:
- rooted device with busybox installed
- a DNS resolver with readable logs. This usually means a local "bind9" installation within the LAN.
- optional: "Script Manager" installed. Makes it easy to experiment and run on network change events.
Code:
#!/system/bin/sh
# trying to direct dns queries to
# private dns resolver in LAN
dns="net.dns"
dns_dflt="${1:-192.168.2.1}"
dns2="${2:-${dns}2}"
boss="${3:-192.168.2.55}"
dns_1=$(getprop "${dns}1")
ex=$?
dns_chg=$(getprop 'net.dnschange')
ex=$(($ex + $?))
echo "$0: id=$(id);dns_1='${dns_1}'"
ping -c1 -w3 "${boss}" &&
case "-${dns_1}" in
-${dns_dflt})
echo "$0: setprop"
setprop "${dns}1" "${boss}"
ex=$(($ex + $?))
setprop "${dns2}" "${dns_1}"
ex=$(($ex + $?))
setprop "net.dnschange" "$((${dns_chg} + 1))"
ex=$(($ex + $?))
;;
esac
getprop | grep 'dns' || :
[ $ex -ne 0 ] && echo "$? setprop '$1' '$2'"
exit $ex
run as root admin user and tick "on network". The output is a list of all current DNS related settings after the script has run.
I use it with the following arguments, which are valid for the "netgear" wlan router and my PCs IP:
192.168.2.1 net.dns2 192.168.2.55
the first is the IP of the DNS server set up in the DHCP lease sent from the router (never changes, used for plausibility test);
the second is the getprop property where the original DNS server will be stored in;
the third is the IP of my own DNS resolver whose logs I can check.
The script makes sure that the resolver is reachable (ping) and that Androids DNS settings are only mutilated when they match expected values (1st argument).

[DEV][MIUI] New Automatic Hardware LED Fix

Hello all,
I wrote this init.d script to be included in the next version of Team M&M's MIUI ROM. Here I am releasing it to the masses for inclusion in your ROM.
Automatically detects/changes light values to switch out framework-res.safe and framework-res.hwled - the script is pretty self explanatory. Enjoy
License...? Whatever you want, GPLv2 I guess. Just don't steal it and claim it as your own, credit would be nice.
Behold:
Code:
# ------------------------------------------------
# Team M&M's MIUI script by CosmicDan
# ------------------------------------------------
# Auto HW_LED fix
# You can change these variables to your liking, but don't blame us for explosions if you get it wrong ;)
# Pretty sure these do nothing anyway since the X10 ambient light sensor is not read by the OS (the LCD
# hardware controls it 100% on it's own AFAIK) but MiUI needs these values otherwise it won't boot.
#
# Second release - also disables "Automatic Brightness" (manual only). You can disable this toggle via XML
# now if you wish ;)
#
my_light_sensor_levels="200,400,1000,3000"
my_light_sensor_lcd_values="35,55,70,70,250"
my_light_sensor_button_values="255,255,0,0,0"
#
# ------------------------------------------------
# ------------------------------------------------
# ------------------------------------------------
# DON'T TOUCH ANYTHING BELOW HERE!
# ------------------------------------------------
# Verbose shell output for debugging purposes
# set -xv
# ------------------------------------------------
# Helper functions
# ------------------------------------------------
dodatabase()
{
if [ "$1" = "1" ];
then
if [ "$2" = "check" ];
then
dosql read "light_screen_dim";
fi
if [ "$2" = "set" ];
then
dosql write 88 "light_screen_dim" "20";
[ "$?" -eq "0" ] && light_screen_dim=20;
fi
fi
if [ "$1" = "2" ];
then
if [ "$2" = "check" ];
then
dosql read light_sensor_custom;
fi
if [ "$2" = "set" ];
then
dosql write 82 light_sensor_custom "1";
[ "$?" -eq "0" ] && light_sensor_custom=1;
fi
fi
if [ "$1" = "3" ];
then
[ "$2" = "check" ] && dosql read light_sensor_levels;
[ "$2" = "set" ] && dosql write 89 light_sensor_levels "$my_light_sensor_levels";
fi
if [ "$1" = "4" ];
then
[ "$2" = "check" ] && dosql read light_sensor_lcd_values;
[ "$2" = "set" ] && dosql write 90 light_sensor_lcd_values "$my_light_sensor_lcd_values";
fi
if [ "$1" = "5" ];
then
[ "$2" = "check" ] && dosql read light_sensor_button_values;
[ "$2" = "set" ] && dosql write 91 light_sensor_button_values "$my_light_sensor_button_values";
fi
if [ "$1" = "6" ];
then
[ "$2" = "check" ] && dosql read light_sensor_keyboard_values;
[ "$2" = "set" ] && dosql write 92 light_sensor_keyboard_values "0,0,0,0,0";
fi
if [ "$1" = "7" ];
then
[ "$2" = "check" ] && dosql read screen_brightness_mode;
[ "$2" = "set" ] && dosql write 25 screen_brightness_mode "0";
fi
}
dosql()
{
if [ "$1" = "read" ];
then
eval "$2"=`sqlite3 -nullvalue 'nullvalue' -column $SETTINGSDB 'SELECT value FROM system WHERE name='\"$2\"';'`;
elif [ "$1" = "write" ];
then
sqlite3 -nullvalue 'nullvalue' -column $SETTINGSDB 'INSERT OR REPLACE INTO system VALUES ('\"$2\"','\"$3\"','\"$4\"');';
echo "[M&M] Changed settings - \"$3\" (at _id $2) to $4";
fi
}
# ------------------------------------------------
# ------------------------------------------------
# ------------------------------------------------
echo "[M&M] Running M&M TEAM Custom Boot Parameters...";
SETTINGSDB=/data/data/com.android.providers.settings/databases/settings.db
if [ -e $SETTINGSDB ];
then
echo "[M&M] Verifying locked settings...";
dodatabase 1 check
if [ ! "$light_screen_dim" = "20" ];
then
dodatabase 1 set
else
echo "[M&M] light_screen_dim already 20, unchanged";
fi
dodatabase 2 check
if [ ! "$light_sensor_custom" = "1" ];
then
dodatabase 2 set
else
echo "[M&M] light_sensor_custom already enabled, unchanged";
fi
# Verify additional settings relating to Display
dodatabase 3 check
if [ ! "$my_light_sensor_levels" = "$light_sensor_levels" ];
then
dodatabase 3 set
else
echo "[M&M] light_sensor_levels already set, unchanged";
fi
dodatabase 4 check
if [ ! "$my_light_sensor_lcd_values" = "$light_sensor_lcd_values" ];
then
dodatabase 4 set
else
echo "[M&M] light_sensor_lcd_values already set, unchanged";
fi
dodatabase 5 check
if [ ! "$light_sensor_button_values" = "255,255,0,0,0" ];
then
dodatabase 5 set
else
echo "[M&M] light_sensor_button_values already set, unchanged";
fi
dodatabase 6 check
if [ ! "$light_sensor_keyboard_values" = "0,0,0,0,0" ];
then
dodatabase 6 set
else
echo "[M&M] light_sensor_keyboard_values already set, unchanged";
fi
dodatabase 7 check
if [ ! "$screen_brightness_mode" = "0" ];
then
dodatabase 7 set
else
echo "[M&M] screen_brightness_mode already manual, unchanged";
fi
else
echo "[M&M] Settings Provider database not found! Factory defaults assumed.";
fi
if [ "$light_screen_dim" -eq "20" ] && [ "$light_sensor_custom" -eq "1" ]; then hw_led=1; fi
if [ "$hw_led" -eq "1" ];
then
if [ -e /system/framework/framework-res.hwled ];
then
echo "[M&M] HW_LED fix is allowed but not enabled yet. Now enabling and clearing dalvik-cache...";
mount -o rw,remount -t yaffs2 /dev/block/mtdblock2 /system;
mv /system/framework/framework-res.apk /system/framework/framework-res.safe;
mv /system/framework/framework-res.hwled /system/framework/framework-res.apk;
mount -o ro,remount -t yaffs2 /dev/block/mtdblock2 /system;
sqlite3 -column $SETTINGSDB 'DROP INDEX systemIndex1;'
sqlite3 -column $SETTINGSDB 'CREATE INDEX systemIndex1 ON system (name);'
rm -r -f /data/dalvik-cache/*
fi
else
if [ -e /system/framework/framework-res.safe ];
then
echo "[M&M] HW_LED fix is NOT allowed yet but still enabled."
echo "[M&M] ...Assumed factory reset performed (or database permissions/integrity error)"
echo "[M&M] ...Now reverting to safe framework and clearing dalvik-cache to prevent bootloop...";
mount -o rw,remount -t yaffs2 /dev/block/mtdblock2 /system;
mv /system/framework/framework-res.apk /system/framework/framework-res.hwled;
mv /system/framework/framework-res.safe /system/framework/framework-res.apk;
mount -o ro,remount -t yaffs2 /dev/block/mtdblock2 /system;
if [ -e $SETTINGSDB ]; then
sqlite3 -column $SETTINGSDB 'DROP INDEX systemIndex1;'
sqlite3 -column $SETTINGSDB 'CREATE INDEX systemIndex1 ON system (name);'
fi
rm -r -f /data/dalvik-cache/*
fi
fi
SETTINGSDB=
light_screen_dim=
light_sensor_custom=
light_sensor_levels=
light_sensor_lcd_values=
light_sensor_button_values=
light_sensor_keyboard_values=
screen_brightness_mode=
my_light_sensor_levels=
my_light_sensor_lcd_values=
hw_led=
echo "[M&M] Custom boot processing complete."
exit 0
Obviously, you have the stock (safe) framework as "framework-res.apk" and then place your HW-LED modified one as framework-res.hwled
The basic summary is that it checks what the values are for display, adjusts them if needed, then enables the hwled fixed version of APK and backing up the old one. In the event of a Factory Reset (i.e. database for Settings Provider not found) it will swap the safe one back in. The user just has to reboot again to get the HW-LED one back, since the settings database has been recreated.
So this means we can finally use the automatic brightness function?
Hzu said:
So this means we can finally use the automatic brightness function?
Click to expand...
Click to collapse
Umm...... no. This is just a script for MIUI cookers and kangers to show that they don't need to make or provide manual enable/disable HWLED FIX ZIP's if they don't want them. This has nothing to do with auto brightness.
The auto-brightness thing in the X10 doesn't work because it's part of the hardware and not software-controlled like other Android phones made after. Maybe FXP developers will get it one day with a new driver but yeah, this is completely unrelated and only applies to address a known MiUI porting issue to X10 with an automatic workaround.
Ah, you mean THAT HW LED. Sorry, got a little bit confused. Shouldn't have read this while in the car.
Haha... yes, well... this is for the MiUI ROM's only. Just an automatic way instead of that whole "Change Dim to 20, reboot, flash ZIP, don't change from 20 again" nonsense. The auto-brightness for X10 I don't think will ever work, I am 90% sure that the ambient light sensor is directly tied to hardware LCD. I'm not just saying this because I'm an X10 fan but I think auto-brightness is pretty crap on most phones I've used anyway (Galaxy S II and HTC Wildfire S)....
....regardless, this fix will be included in Team M&M's MiUI v7 due for release soon. The ROM also completely disables the automatic brightness settings via Settings.apk XML editing, because they are useless.
Also, script in OP updated I'm sure at least one MiUI Dev for X10 will find this useful, if they want to compete with Team M&M that is
Yes, the auto brightness won't work due to lack of hardware Support. And I've tried the auto brightness setting on my friend's phone (I forgot the model) and its actually... very annoying to me.

[Q] Need help for executing a script

HI, I'm trying to extract initramfs from zImage by following this excellent thread:
http://forum.xda-developers.com/showthread.php?t=901152
I have followed carefully all the steps but i am getting the following error while executing the extraction script :
# sh repack-zImage.sh -u
repack-zImage.sh: 99: Syntax error: "(" unexpected
How can i resolve this please.
here is the sript :
Code:
#!/bin/bash
version="Version 6, by mizch <[email protected]>
Time-stamp: <2011-05-03 20:14:30 hcz>
Please refer to the thread on http://www.xda-developers.com for
questions and remarks about this program."
# Copyright (C) 2011 by Heike C. Zimmerer <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. For
# details see <http://www.gnu.org/licenses/>.
### Preparation:
# You should have received cpio_set0 along with this program.
# Copy it into /usr/local/bin.
#
# The program will run without this (and emit an info message about
# using the normal cpio). However, the compession result of the
# initramfs will be smaller and consistent if you use it.
### What the program does:
usage(){
echo "\
Usage: $pname [-v] -u|-p|-z [<file name, default: zImage>]
Function: [Un]Pack a zImage (for modification, mainly of the initramfs)
Opts:
-u unpack an Image
-p pack an image from a directory structure created by
a previous unpack
-z create <file name>.tar from <file name> (simple tar, nothing fancy)
--version print version info
--help print this help
Play with the following three options to get best compression results:
-s use standard cpio (default: uses cpio_set0 if available)
-g use gen_init_cpio instead of cpio/cpio_set0 (ignores -s)
-r don't reorder initramfs according to the original layout
Debugging:
-v verbose (show commands and results as they are executed)
-x script debug (set -x)
Options to help nail down which modified part causes booting to fail.
Lower numbers override higher numbered options:
-1 Use original piggy.gz+piggy_trailer
-2 Use original piggy.gz
-3 Use original piggy
-4 Use original initramfs(_gz)+part3
-5 Use original initramfs_cpio"
exit $1
}
### Graphical display of the unpack process:
#
# Each of the indented items on the same level is derived from the
# single item one level higher.
#
# zImage
# (split)
# +---- decompression_code
# +---- piggy.gz+piggy_trailer
# (split)
# +---- piggy.gz
# | (gunzip)
# | +---- piggy
# | ===== either (compressed initramfs) ====
# | |
# | (split via gunzip limits)
# | +---- kernel.img
# | +---- initramfs_gz+part3
# | (split)
# | +---- initramfs.cpio.gz
# | | (gunzip)
# | | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# | ===== or (uncompressed initramfs) =====
# | |
# | (split at "0707")
# | +---- kernel.img
# | +---- initramfs+part3
# | (split after "TRAILER!!!")
# | +---- initramfs.cpio
# | | (cpio -i)
# | | +---- initramfs/
# | +---- padding3
# | +---- part3
# +---- padding_piggy
# +---- piggy_trailer
#
#
pname="${0##*/}"
args=("[email protected]")
cur_dir="$(pwd)"
# file names:
decompression_code="decompression_code"
piggy_gz_piggy_trailer="piggy.gz+piggy_trailer"
piggy="piggy"
piggy_gz="piggy.gz"
padding_piggy="padding_piggy"
piggy_trailer="piggy_trailer"
ramfs_gz_part3="initramfs.cpio+part3"
ramfs_cpio_gz="initramfs.cpio.gz"
padding3="padding3"
part3="part3"
kernel_img="kernel.img"
ramfs_cpio="initramfs.cpio"
ramfs_dir="initramfs"
sizes="sizes"
ramfs_part3="ramfs+part3"
ramfs_list="initramfs_list"
cpio_t="cpio-t"
cpio="cpio_set0"
# We dup2 stderr to 3 so an error path is always available (even
# during commands where stderr is redirected to /dev/null). If option
# -v is set, we dup2 sterr to 9 also so commands (and some of their
# results if redirected to &9) are printed also.
exec 9>/dev/null # kill diagnostic ouput (will be >&2 if -v)
exec 3>&2 # an always open error channel
#
########### Start of functions
#
# Emit an error message and abort
fatal(){
# Syntax: fatal <string ...>
# Output error message, then abort
echo >&3
echo >&3 "$pname: $*"
kill $$
exit 1
}
# Execute a command, displaying the command if -v:
cmd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo command line if -v
echo >&9 "$*"
"[email protected]"
}
# Execute a required command, displaying the command if -v, abort on
# error:
rqd(){
# Syntax: cmd <command> <args...>
# Execute <command>, echo commandline if -v, abort on error
cmd "[email protected]" || fatal "$* failed."
}
relpath(){
# Syntax: relpath <absolute_path>
# Function: print a path below $cur_dir as relative path on stdout
if [ "${1#$cur_dir}" != "$1" ]; then
echo -n ".${1#$cur_dir}"
else # not below cur_dir
echo -n "$1"
fi
}
findByteSequence(){
# Syntax: findByteSequence <fname> [<string, default: gzip header>]
# Returns: position (offset) on stdout, empty string if nothing found
file="$1"
local opt
if [ "$2" = "lzma" ]; then
srch=$'\x5d....\xff\xff\xff\xff\xff'
opt=
else
srch="${2:-$'\x1f\x8b\x08'}" # Default: search for gzip header
opt="-F"
fi
pos=$(LC_ALL=C grep $opt -a --byte-offset -m 1 --only-matching -e "$srch" -- "$file")
echo ${pos%%:*}
}
getFileSize(){
# Syntax: getFileSize <file>
# Returns size of the file on stdout.
# Aborts if file doesn't exist.
rqd stat -c %s "$1"
}
recordPackingFileSize()(
# Syntax: recordPackingFileSize <file-var> ...
#
# dump out a file size from the packing directory for debugging.
# Note that the whole function is running in a subshell, so we can
# cd here.
rqd cd "$packing"
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
)
recordFileSize(){
# Syntax: recordFileSize <file-var> ...
# Dump a file size from the current directory into $sizes for
# later sourcing as a shell script.
for file in "[email protected]"; do
eval local fnam=\$$file
local size=$(getFileSize "$fnam")
printf 'size_%s=%d # %#x\n' $file $size $size
done >> "$sizes"
}
recordVars(){
# Syntax dumpVar <var-name>
# Dumps var into file $sizes for later sourcing as a shell script
for var in "[email protected]"; do
eval printf '"%s=\"%s\"\n"' $var \$$var \$$var
done >> "$sizes"
}
checkNUL(){
# Syntax: checkNUL file offset
# Returns true (0) if byte there is 0x0.
[ "$(rqd 2>/dev/null dd if="$1" skip=$2 bs=1 count=1)" = $'\0' ]
}
# We can tell from the magic number where the start of a gzipped
# section is. We cannot tell its exact end. We could only know the
# end if we could get at the kernel's zeropage variables - which we
# can't since their position varies between versions and
# architectures. The following function separates the gzipped part
# from trailing bytes (which can be possibly garbage, but who knows?)
# via successive aproximation.
gunzipWithTrailer(){
# Syntax gunzipWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the gzipped part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/gunzipWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=0
echo "Separating gzipped part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd gunzip >/dev/null 2>&1 -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ]; then
: $((at_min++))
results_at_min[$size]=1
[ "$at_min" -gt 3 ] && break
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 2: trailing garbage
2) size=$((size-d)); direction="↓";;
# OK
0) break;;
*) fatal "gunzip returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
if [ "$at_min" -gt 3 ]; then
echo -e "\ngunzip result is oscillating between 'too small' and 'too large' at size: ${!results_at_min[*]}"
echo -n "Trying lower nearby values: "
fini=
for ((d=1; d < 30; d++)); do
: $((size--))
echo -n " $size"
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
if cmd gunzip >/dev/null 2>&1 -c "$tmpfile"; then
echo -n " - OK"
fini=1
break
fi
done
[ -z "$fini" ] && fatal 'oscillating gunzip result, giving up.'
fi
# We've found the end of the gzipped part. This is not the real
# end since gzip allows for some trailing padding to be appended
# before it barfs. First, go back until we find a non-null
# character:
echo -ne "\npadding check (may take some time): "
real_end=$((size-1))
while checkNUL "$file" $real_end; do
: $((real_end--))
done
# Second, try if gunzip still succeeds. If not, add trailing
# null(s) until it succeeds:
while :; do
rqd dd if="$file" of="$tmpfile" bs=$real_end count=1 2>/dev/null
gunzip >/dev/null 2>&1 -c "$tmpfile"
case $? in
# 1: too small
1) : $((real_end++));;
*) break;;
esac
done
real_next_start=$size
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd gunzip -c "$gz_result" > "$result"
}
# See the comment for gunzipWithTrailer (above) for what this function
# does:
unlzmaWithTrailer(){
# Syntax unlzmaWithTrailer <file> <gzip name, sans .gz> <padding> <trailer>
#
# <file>: the input file
# <gzip name, sans .gz>, <padding>, <trailer>:
# The output files. For the lzma'd part, both the
# compressed and the uncompressed output is generated, so we have
# 4 output files.
local file="$1"
local gz_result="$2.gz"
local result="$2"
local padding="$3"
local trailer="$4"
local tmpfile="/tmp/unlzmaWithTrailer.$$.gz"
local original_size=$(getFileSize "$file")
local d=$(( (original_size+1) / 2))
local direction fini at_min=0
local results_at_min=()
local size=$d
local at_min=
echo "Separating lzma'd part from trailer in '$(relpath "$file")'"
echo -n "Trying size: $size"
while :; do
rqd dd if="$file" of="$tmpfile" bs=$size count=1 2>/dev/null
cmd unlzma >/dev/null 2>&1 -S '' -c "$tmpfile"
res=$?
if [ "$d" -eq 1 ] && [ "$res" -eq 1 ]; then
at_min=yes # we're 1 below the result
fi
d=$(((d+1)/2))
case $res in
# 1: too small
1) size=$((size+d)); direction="↑";;
# 0: too large (or OK if d==1)
0) if [ "$at_min" ]; then
break
fi
size=$((size-d)); direction="↓";;
*) fatal "unlzma returned $res while checking '$(relpath "$file")'";;
esac
echo -n " $size"
done
# Now, skip NULs forward until we reach a non-null byte. This is
# considered as being the start of the next part.
echo
echo -n "Detecting padding: "
real_end="$size"
real_next_start="$size"
while checkNUL "$file" $real_next_start; do
: $((real_next_start++))
done
echo $((real_next_start - real_end))
echo
rm "$tmpfile"
# Using the numbers we got so far, create the output files which
# reflect the parts we've found so far:
rqd dd 2>&9 if="$file" of="$gz_result" bs=$real_end count=1
rqd dd 2>&9 if="$file" of="$padding" skip=$real_end bs=1 count=$((real_next_start - real_end))
rqd dd 2>&9 if="$file" of="$trailer" bs=$real_next_start skip=1
rqd unlzma -c -S '' "$gz_result" > "$result"
}
padTo(){
# Syntax: padTo <file> <size>
# Pads <file> to <size> with trailung 0x0s
# Does nothing if file matches size.
# Aborts if <file> too large for the operation.
local size=$(getFileSize "$1")
local tmp="/tmp/$pname.$$.zeroes"
if [ "$size" -eq "$2" ]; then
echo "$(relpath "$1"): size matches ($size)"
elif [ "$size" -gt "$2" ]; then
fatal "Size of '$(relpath "$1")' too large ($size > $2) (+$((size - $2)))"
else
echo "Padding '$(relpath "$1")' to $2 bytes (+$(($2 - size)))"
rqd dd 2>&9 if=/dev/zero of="$tmp" count=1 bs=$(($2 - size))
rqd cat "$tmp" >> "$1"
rqd rm -f "$tmp"
fi
}
padToMod(){
# Syntax: padTo <modulo> <file>
# Pads <file> until (size mod <modulo>) == 0.
local modulo=$1
local file="$2"
local size=$(getFileSize "$file")
local rest=$((size % modulo))
if [ "$rest" -ne 0 ]; then
padTo "$file" $((size + modulo - rest))
fi
}
buildZImageTar(){
# Syntax: buildZImageTar <path>
# Generates tarred file from <path> into the same directory.
# The file in the archive doesn't contain the path.
# Also copies the result to /home/Shared if it detects
# that it is running at home.
local dir="${1%/*}"/
[ "$dir" = "$1/" ] && dir="$(pwd)/"
(
cd "$dir"
rqd tar cf zImage.tar zImage
)
echo "Generated file: '$(relpath "${dir}$zImage.tar")'"
if [ "$HOSTNAME:$USER" = "Xelzbrot:hcz" ]; then
cp "${dir}zImage.tar" /home/Shared
echo "also copied to '/home/Shared'."
fi
}
reorderInitramfsList(){
# This is some black magic to get about the same compression
# result as the original initramfs.cpio. We reorder the files in
# our initramfs (which is to be created) so that they appear in
# the same order as in the original initramfs.
#
# Syntax: reorderInitramfsList <initramfs_list_file> <reordering_template_file>
#
# Reorders <initramfs_list_file> so that enries are in the order
# given by <reordering_template_file> (which comes from cpio -t).
# Files in <initramfs_list_file> but not in
# <reordering_template_file> are moved in sorted order to the end.
# Comments and empty lines are discarded. The result is written
# to <initramfs_list_file>.
#echo >&2 "Reordering initramfs list"
initramfs_list_file="$1"
reordering_template_file="$2"
declare -A ramfs_entries # make it an associative array
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
ramfs_entries["$2"]="$line" # else remember line, indexed by path
done < "$initramfs_list_file"
echo "# reordered ramfs entries" > "$initramfs_list_file"
# now spit the lines out in the order given by the reordering_template_file:
while read path; do
echo "${ramfs_entries["$path"]}"
unset ramfs_entries["$path"] # remove written lines from the array
done < "$reordering_template_file" >> "$initramfs_list_file"
# if there are any files left, append them in sorted order so directories
# come first:
for line in "${ramfs_entries[@]}"; do
echo "$line"
done \
| sort >> "$initramfs_list_file"
}
pack(){
if ! find >/dev/null 2>&1 "$unpacked" "$unpacked/$ramfs" "$unpacked/$sizes" -maxdepth 0; then
fatal "\
This does not look like a directory where a
previous unpack has been done."
fi
# create packing direcory
rqd mkdir -p "$packing"
sizes="$packing/sizes"
echo "# Packing sizes" > "$sizes"
# cd to unpacking directory (original and modified parts)
rqd cd "$unpacked"
# read in file size at the time of unpicking
rqd source sizes
if [ "$opt_1" ]; then
rqd cp "$piggy_gz_piggy_trailer" "$packing"
else
if [ "$opt_2" ]; then
rqd cp "$piggy_gz" "$packing"
else
if [ "$opt_3" ]; then
rqd cp "$piggy" "$packing"
compress_list=("$packing/$piggy") # compress it as a single file
else
if [ "$opt_4" ]; then
rqd cp "$ramfs_gz_part3" "$packing"
else
if [ "$opt_5" ]; then
rqd cp "$ramfs_cpio" "$packing"
else
echo "Generating initramfs"
if ! which >/dev/null "$cpio"; then
if [ -n "$compressed" ]; then
echo "Info: '$cpio' not found, using normal cpio."
echo " This only means that your compressed initramfs will be slightly larger"
echo " and its size will differ from invocation to invocation."
fi
cpio="cpio"
fi
for ftime in "" "-a" "-m"; do
find "$ramfs_dir" -exec touch $ftime -d @0 {} \;
done
rqd gen_initramfs_list.sh -u squash -g squash "$ramfs_dir" > "$packing/$ramfs_list"
cp "$packing/$ramfs_list" "$packing/$ramfs_list.orig"
if [ -z "$opt_r" ]; then
# reorder so files are arranged as in original initramfs:
reorderInitramfsList "$packing/$ramfs_list" "$cpio_t"
else
# sort so directories come before their content:
sort < "$cpio_t" > "$packing/$cpio_t.sorted"
reorderInitramfsList "$packing/$ramfs_list" "packing/$cpio_t.sorted"
fi
if [ -z "$opt_g" ]; then
# No -g: Use our own cpio routine
(
rqd cd "$ramfs_dir"
# extract the file names from our
# (possibly reordered) initramfs list
# and pass them to cpio:
while read line; do
set -- $line
[ $# -eq 0 ] && continue # skip empty lines
[[ "$1" = \#* ]] && continue # skip comments
echo "${2#/}"
done < "$packing/$ramfs_list" \
| rqd "$cpio" -H newc -R root:root -o > "$packing/$ramfs_cpio"
)
else
# -g set: use gen_init_cpio (from kernel tree)
rqd gen_init_cpio "$packing/$ramfs_list" > "$packing/$ramfs_cpio"
fi
recordPackingFileSize ramfs_cpio
fi # opt_5
if [ "$compressed" = "gz" ]; then
echo "Creating gzip compressed initramfs"
rqd gzip -8 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
elif [ "$compressed" = "lzma" ]; then
echo "Creating lzma compressed initramfs"
rqd lzma -9 < "$packing/$ramfs_cpio" > "$packing/$ramfs_cpio_gz"
padTo "$packing/$ramfs_cpio_gz" "$((size_ramfs_cpio_gz + size_padding3))"
rqd cat "$packing/$ramfs_cpio_gz" "$part3" > "$packing/$ramfs_gz_part3"
recordPackingFileSize ramfs_cpio_gz ramfs_gz_part3
else
echo "initramfs is not compressed"
fi
fi # opt_4
echo "Assembling piggy"
if [ -n "$compressed" ]; then
rqd cat "$kernel_img" "$packing/$ramfs_gz_part3" > "$packing/$piggy"
compress_list=("$packing/$piggy") # compress it as a single file
else
#touch "$packing/$padding3"
#padTo "$packing/$padding3" "$size_padding3"
padTo "$packing/$ramfs_cpio" $((size_ramfs_cpio + size_padding3))
# compress parts seperately (yields better compression results):
cat "$kernel_img" "$packing/$ramfs_cpio" "$part3" > "$packing/$piggy"
recordPackingFileSize "piggy"
compress_list=("$packing/$piggy")
fi
fi # opt_3
echo "Creating piggy.gz"
target_size=$((size_piggy_gz + size_padding_piggy))
# At first, use gzip -9 for compressing since it delivers
# better results with zImages most of the time:
rqd gzip -n -9 -c "${compress_list[@]}" > "$packing/$piggy_gz"
size1=$(getFileSize "$packing/$piggy_gz")
if [ "$size1" -gt "$target_size" ]; then
# too large. Try if we can get better results with
# gzip -8. If not, barf and abort:
rqd gzip -8 -n -c "${compress_list[@]}" > "$packing/$piggy_gz"
size2=$(getFileSize "$packing/$piggy_gz")
if [ "$size2" -gt "$target_size" ]; then
fatal "\
piggy.gz too large (gzip -9: +$((size1-target_size)), gzip -8: +$((size2-target_size)))
You might want to try a different combination of the -g, -r and -s options."
fi
fi
padTo "$packing/$piggy_gz" "$((size_piggy_gz + size_padding_piggy))"
recordPackingFileSize "piggy_gz"
fi # opt_2
echo "Assembling $zImage"
rqd cat "$packing/$piggy_gz" "$piggy_trailer" > "$packing/$piggy_gz_piggy_trailer"
fi # opt_1
rqd cat "$decompression_code" "$packing/$piggy_gz_piggy_trailer" \
> "$packing/$zImage"
echo "Successfully created '$(relpath "$packing/$zImage")'"
recordPackingFileSize zImage
buildZImageTar "$packing/$zImage"
}
unpack()(
[ -d "$unpacked" ] && echo "\
Warning: there is aready an unpacking directory. If you have files added on
your own there, the repacking result may not reflect the result of the
current unpacking process."
rqd mkdir -p "$unpacked"
rqd cd "$unpacked"
sizes="$unpacked/sizes"
echo "# Unpacking sizes" > "$sizes"
piggy_start=$(findByteSequence "$cur_dir/$zImage")
if [ -z "$piggy_start" ]; then
fatal "Can't find a gzip header in file '$zImage'"
fi
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" count=1 of="$decompression_code"
rqd dd 2>&9 if="$cur_dir/$zImage" bs="$piggy_start" skip=1 of="$piggy_gz_piggy_trailer"
recordFileSize decompression_code piggy_gz_piggy_trailer
gunzipWithTrailer "$piggy_gz_piggy_trailer" \
"$piggy" "$padding_piggy" "$piggy_trailer"
recordFileSize "piggy" "piggy_gz" "padding_piggy" "piggy_trailer"
ramfs_gz_start=$( findByteSequence "$piggy" lzma)
if [ -n "$ramfs_gz_start" ]; then
echo "Found lzma compressed ramdisk."
compressed=lzma
else
ramfs_gz_start=$( findByteSequence "$piggy")
if [ -n "$ramfs_gz_start" ]; then
echo "Found gzip compressed ramdisk."
compressed=gz
fi
fi
if [ "$compressed" ]; then
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$ramfs_gz_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_gz_part3" bs="$ramfs_gz_start" skip=1
if [ "$compressed" = "gz" ]; then
rqd gunzipWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
else
rqd unlzmaWithTrailer "$ramfs_gz_part3" "$ramfs_cpio" "$padding3" "$part3"
fi
recordFileSize "kernel_img" "ramfs_cpio_gz" "padding3" "ramfs_gz_part3" "ramfs_cpio" "part3"
recordVars compressed
else
echo "Found uncompressed ramdisk."
compressed=""
initrd_start=$(findByteSequence "$piggy" "0707")
[ -z "$initrd_start" ] && fatal "Cannot find cpio header"
rqd dd 2>&9 if="$piggy" of="$kernel_img" bs="$initrd_start" count=1
rqd dd 2>&9 if="$piggy" of="$ramfs_part3" bs="$initrd_start" skip=1
initrd_end=$(findByteSequence "$ramfs_part3" "TRAILER!!!")
[ -z "$initrd_end" ] && fatal "Cannot find cpio trailer"
initrd_end=$((initrd_end + 10)) # skip trailer length
initrd_end=$(( (initrd_end | 0x1ff) + 1)) # round up to block size (512)
rqd dd 2>&9 if="$ramfs_part3" of="$ramfs_cpio" bs="$initrd_end" count=1
real_next_start=$initrd_end
echo -n "Detecting padding (may take some time): "
while checkNUL "$ramfs_part3" $real_next_start; do
: $((real_next_start++))
done
padding3_len=$((real_next_start - initrd_end))
echo $padding3_len
rqd dd 2>&9 if="$ramfs_part3" of="$padding3" skip="$initrd_end" count="$padding3_len" bs=1
rqd dd 2>&9 if="$ramfs_part3" of="$part3" bs="$real_next_start" skip=1
recordFileSize "kernel_img" "padding3" "ramfs_part3" "ramfs_cpio" "part3"
recordVars compressed
fi
echo "Unpacking initramfs"
rqd cpio -t < "$ramfs_cpio" > "$cpio_t"
rqd mkdir -p "$ramfs_dir"
(
rqd cd "$ramfs_dir"
rqd cpio -i -m --no-absolute-filenames -d -u < "../$ramfs_cpio"
)
echo
echo "Success."
echo "The unpacked files and the initramfs directory are in '$(relpath "$unpacked")'."
)
#### start of main program
while getopts xv12345sgrpuhtz-: argv; do
case $argv in
p|u|z|1|2|3|4|5|t|r|g) eval opt_$argv=1;;
v) exec 9>&2; opt_v=1;;
s) cpio="cpio";;
x) set -x;;
-) if [ "$OPTARG" = "version" ]; then
echo "$pname $version"
exit 0
else
usage
fi;;
h|-) usage;;
*) fatal "Illegal option";;
esac
done
shift $((OPTIND-1))
zImage="${1:-zImage}"
unpacked="$cur_dir/${zImage}_unpacked"
packing="$cur_dir/${zImage}_packing"
shift
if [ -n "$*" ]; then
fatal "Excess arguments: '$*'"
fi
if [ -n "$opt_z" ]; then
buildZImageTar "$zImage"
fi
if [ -n "$opt_u" ]; then
[ -f "$zImage" ] || fatal "file '$zImage': not found"
unpack
fi
if [ -n "$opt_p" ]; then
pack
fi
#if [ -n "$opt_t" ]; then # for testing
# reorderInitramfsList "$packing/$ramfs_list" "$unpacked/$cpio_t"
#fi
if [ -z "$opt_p$opt_u$opt_z$opt_t" ]; then
echo >&2 "$pname: Need at least one of -u, -p, or -z."
echo >&2 "$pname: Type '$pname --help' for usage info."
exit 1
fi
exit
Solved. (by using bash instead of sh)..

Reverse Tether

I currently run Paranoid Android on my SG5, which works well enough for my tastes. One thing I've wanted to play with is reverse tethering. Since I charge my player via the computer's usb connection, I figured it'd make sense to disable wifi and save a little power to speed up the slow usb charging and just use the pc's internet connection via usb. I also have a few apps like calibre and the compantion app which don't work correctly when I'm on a wifi connection that's been firewalled to prevent devices from communicating with each other. This bypasses the wifi connection and gives me a nice secure connection between devices.
I got it working ... mostly. I don't expect many people to find this useful, but I thought it might be an entertaining hack to poke at.
The following script sits on my linux netbooks' ~/bin directory as reverse-tether.sh
Code:
#!/bin/sh
# We need root on the host to mess with networking
if [[ $(whoami) != "root" ]]; then
echo "You must be root to run this script!"
exit 1
fi;
# We need root on the Player to mess with networking
echo 'Enabling adb root access...'
adb -d root
# Turn on usb networking
echo 'Enabling usb network interface on the Galaxy Player...'
adb -d shell 'sh /storage/sdcard0/reverse_tether.sh up &'
# adb disconnects, so we wait for the network on the player to settle before continuing on.
sleep 2
# Rename device interface as ArchLinux has annoying device names (becomes player)
IF=`ifconfig -a | grep "enp" | cut -d ':' -f 1`
ip link set dev $IF down
/usr/sbin/ifrename -i $IF -n player
ip link set dev player up
echo 'Setting Computer IP Address ...'
ifconfig player 192.168.200.1 netmask 255.255.255.0
ifconfig player up
echo 'Enabling NAT and IP Forwarding on Computer...'
# Start forwarding and nat (use existing default gw)
iptables -F -t nat
iptables -A POSTROUTING -t nat -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 'Starting dnsmasq on Computer...'
dnsmasq --interface=player --no-dhcp-interface=player
echo
echo 'Connection is ready! Press any key to shutdown.'
echo
read
echo 'Shutting down reverse tethering'
# SSH server is always running on player, with public rsa key imported for passwordless logins
# This hackery is required as adb seems to be disabled with rndis active.
# I use dropbear server II, but any of the ssh servers would probably work.
ssh [email protected] 'sh /storage/sdcard0/reverse_tether.sh down &'
killall dnsmasq
ifconfig player down
iptables -F -t nat
echo 0 > /proc/sys/net/ipv4/ip_forward
And the following script is simply stashed on the sdcard of the player. as /storage/sdcard0/reverse_tether.sh
Code:
#!/system/bin/sh
if [ "$1" = "up" ]; then
echo 1 > /sys/class/usb_composite/rndis/enable
ip addr add 192.168.200.2/24 dev usb0
ip link set usb0 up
ip route delete default
ip route add default via 192.168.200.1
setprop net.dns1 192.168.200.1
fi
if [ "$1" = "down" ]; then
sleep 2
ip route delete default
ip link set usb0 down
echo 0 > /sys/class/usb_composite/rndis/enable
fi
When I finish, sometimes I need to restart wifi on the player to get networking to work again.
The only real problem I've had is that some apps require or want wifi/3g active in order to fully function. For example, the play store works fine until you try and download an actual update. Google Maps works fine, although you get lots of warnings about having wifi turned off. I have no idea how to "emulate" 3g or wifi which I think would solve that problem.
This was fun getting running. Hope you enjoyed...
I know this is an old thread but I found this really really useful. Going to give it a try after work today. Great job.
Sent from my YP-G70 using xda app-developers app

[Q] How to edit "init.qcom.bt.sh" to set static mac adress?

I have problem with changing bluetooth mac adress in my phone:
CPU Qualcomm MSM8225Q 4 x 1,2 GHz; GPU Adreno 203; Android 4.1.2 Jelly Bean
After paring phone with pc and switch of bluetooth, next time i must paring one more time.
I find reason this problems, mac adress in phone is changing .
Can someone help me edit file to set static MAC adress and device name?
Can I change adress in this file?
If not, where I can do this?
I think
- add in file:
Code:
BTS_ADDRESS="00:a0:c6:90:03:b6"
- change in function
Code:
start_hciattach ()
{
/system/bin/hciattach -n $BTS_DEVICE $BTS_TYPE $BTS_BAUD &
hciattach_pid=$!
logi "start_hciattach: pid = $hciattach_pid"
echo 1 > $BLUETOOTH_SLEEP_PATH
}
Code:
#!/system/bin/sh
# Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of The Linux Foundation nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#Read the arguments passed to the script
config="$1"
BLUETOOTH_SLEEP_PATH=/proc/bluetooth/sleep/proto
LOG_TAG="qcom-bluetooth"
LOG_NAME="${0}:"
hciattach_pid=""
loge ()
{
/system/bin/log -t $LOG_TAG -p e "$LOG_NAME [email protected]"
}
logi ()
{
/system/bin/log -t $LOG_TAG -p i "$LOG_NAME [email protected]"
}
failed ()
{
loge "$1: exit code $2"
exit $2
}
program_bdaddr ()
{
/system/bin/btnvtool -O
logi "Bluetooth Address programmed successfully"
}
#
# enable bluetooth profiles dynamically
#
config_bt ()
{
baseband=`getprop ro.baseband`
target=`getprop ro.board.platform`
soc_hwid=`cat /sys/devices/system/soc/soc0/id`
btsoc=`getprop qcom.bluetooth.soc`
case $baseband in
"apq")
setprop ro.qualcomm.bluetooth.opp true
setprop ro.qualcomm.bluetooth.ftp true
setprop ro.qualcomm.bluetooth.nap false
setprop ro.qualcomm.bluetooth.sap false
setprop ro.qualcomm.bluetooth.dun false
# For MPQ as baseband is same for both
case $soc_hwid in
"130")
setprop ro.qualcomm.bluetooth.hsp true
setprop ro.qualcomm.bluetooth.hfp true
setprop ro.qualcomm.bluetooth.pbap false
setprop ro.qualcomm.bluetooth.map false
;;
*)
setprop ro.qualcomm.bluetooth.hsp false
setprop ro.qualcomm.bluetooth.hfp false
setprop ro.qualcomm.bluetooth.pbap true
setprop ro.qualcomm.bluetooth.map true
;;
esac
;;
"mdm" | "svlte2a" | "svlte1" | "csfb")
setprop ro.qualcomm.bluetooth.opp true
setprop ro.qualcomm.bluetooth.hfp true
setprop ro.qualcomm.bluetooth.hsp true
setprop ro.qualcomm.bluetooth.pbap true
setprop ro.qualcomm.bluetooth.ftp true
setprop ro.qualcomm.bluetooth.map true
setprop ro.qualcomm.bluetooth.nap true
setprop ro.qualcomm.bluetooth.sap true
setprop ro.qualcomm.bluetooth.dun false
;;
"msm")
setprop ro.qualcomm.bluetooth.opp true
setprop ro.qualcomm.bluetooth.hfp true
setprop ro.qualcomm.bluetooth.hsp true
setprop ro.qualcomm.bluetooth.pbap true
setprop ro.qualcomm.bluetooth.ftp true
setprop ro.qualcomm.bluetooth.nap true
setprop ro.qualcomm.bluetooth.sap true
setprop ro.qualcomm.bluetooth.dun true
case $btsoc in
"ath3k")
setprop ro.qualcomm.bluetooth.map false
;;
*)
setprop ro.qualcomm.bluetooth.map true
;;
esac
;;
*)
setprop ro.qualcomm.bluetooth.opp true
setprop ro.qualcomm.bluetooth.hfp true
setprop ro.qualcomm.bluetooth.hsp true
setprop ro.qualcomm.bluetooth.pbap true
setprop ro.qualcomm.bluetooth.ftp true
setprop ro.qualcomm.bluetooth.map true
setprop ro.qualcomm.bluetooth.nap true
setprop ro.qualcomm.bluetooth.sap true
setprop ro.qualcomm.bluetooth.dun true
;;
esac
#Enable Bluetooth Profiles specific to target Dynamically
case $target in
"msm8960")
if [ "$btsoc" != "ath3k" ] && [ "$soc_hwid" != "130" ]
then
setprop ro.bluetooth.hfp.ver 1.6
setprop ro.qualcomm.bt.hci_transport smd
fi
;;
*)
;;
esac
}
start_hciattach ()
{
/system/bin/hciattach -n $BTS_DEVICE $BTS_TYPE $BTS_BAUD &
hciattach_pid=$!
logi "start_hciattach: pid = $hciattach_pid"
echo 1 > $BLUETOOTH_SLEEP_PATH
}
kill_hciattach ()
{
echo 0 > $BLUETOOTH_SLEEP_PATH
logi "kill_hciattach: pid = $hciattach_pid"
## careful not to kill zero or null!
kill -TERM $hciattach_pid
# this shell doesn't exit now -- wait returns for normal exit
}
logi "init.qcom.bt.sh config = $config"
case "$config" in
"onboot")
program_bdaddr
config_bt
exit 0
;;
*)
;;
esac
# mimic hciattach options parsing -- maybe a waste of effort
USAGE="hciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]"
while getopts "blnpt:s:" f
do
case $f in
b | l | n | p) opt_flags="$opt_flags -$f" ;;
t) timeout=$OPTARG;;
s) initial_speed=$OPTARG;;
\?) echo $USAGE; exit 1;;
esac
done
shift $(($OPTIND-1))
# Note that "hci_qcomm_init -e" prints expressions to set the shell variables
# BTS_DEVICE, BTS_TYPE, BTS_BAUD, and BTS_ADDRESS.
#Selectively Disable sleep
BOARD=`getprop ro.board.platform`
# BR/EDR & LE power class configurations
POWER_CLASS=`getprop qcom.bt.dev_power_class`
LE_POWER_CLASS=`getprop qcom.bt.le_dev_pwr_class`
#find the transport type
TRANSPORT=`getprop ro.qualcomm.bt.hci_transport`
logi "Transport : $TRANSPORT"
case $POWER_CLASS in
1) PWR_CLASS="-p 0" ;
logi "Power Class: 1";;
2) PWR_CLASS="-p 1" ;
logi "Power Class: 2";;
3) PWR_CLASS="-p 2" ;
logi "Power Class: CUSTOM";;
*) PWR_CLASS="";
logi "Power Class: Ignored. Default(1) used (1-CLASS1/2-CLASS2/3-CUSTOM)";
logi "Power Class: To override, Before turning BT ON; setprop qcom.bt.dev_power_class <1 or 2 or 3>";;
esac
case $LE_POWER_CLASS in
1) LE_PWR_CLASS="-P 0" ;
logi "LE Power Class: 1";;
2) LE_PWR_CLASS="-P 1" ;
logi "LE Power Class: 2";;
3) LE_PWR_CLASS="-P 2" ;
logi "LE Power Class: CUSTOM";;
*) LE_PWR_CLASS="-P 1";
logi "LE Power Class: Ignored. Default(2) used (1-CLASS1/2-CLASS2/3-CUSTOM)";
logi "LE Power Class: To override, Before turning BT ON; setprop qcom.bt.le_dev_pwr_class <1 or 2 or 3>";;
esac
eval $(/system/bin/hci_qcomm_init -e $PWR_CLASS $LE_PWR_CLASS && echo "exit_code_hci_qcomm_init=0" || echo "exit_code_hci_qcomm_init=1")
case $exit_code_hci_qcomm_init in
0) logi "Bluetooth QSoC firmware download succeeded, $BTS_DEVICE $BTS_TYPE $BTS_BAUD $BTS_ADDRESS";;
*) failed "Bluetooth QSoC firmware download failed" $exit_code_hci_qcomm_init;;
esac
# init does SIGTERM on ctl.stop for service
trap "kill_hciattach" TERM INT
case $TRANSPORT in
"smd")
echo 1 > /sys/module/hci_smd/parameters/hcismd_set
;;
*)
logi "start hciattach"
start_hciattach
wait $hciattach_pid
logi "Bluetooth stopped"
;;
esac
exit 0

Categories

Resources