Ok, I didn't like to open a new thread about OBEX and android, but, as I explain in this post http://forum.xda-developers.com/showpost.php?p=3932525&postcount=57 , I got OBEX working in my G1, and now I'm thinking about integrating a clean and elegant OBEX support into our ROMS.
Yes, there is already an application in the market for receiving and sending files via OBEX, but I simply don't like to pay for a feature that should be supported by default in every mobile phone.
I was wondering how would be the first approach for integrating the obexserver by default, and it would be really easy executing at boot time something like:
Code:
sdptool add --channel=4 OPUSH
test -d /sdcard/bluetooth_received || mkdir /sdcard/bluetooth_received
cd /sdcard/bluetooth_received && ( while true; do obexserver; done ) &
The only problem, is that disabling bluetooth and enabling it again, it loses the OPUSH service added by sdptool.
So, I'm now trying to find a way to tell the bluetooth daemons that they should add the OPUSH service when they are enabled, and here is where I need your help. Anybody knows how can this be done?
Also, another way would be simply executing a GScript when the OPUSH service is needed.
What do you think?
Thanks!
EDIT: Here is a simple script that enables the OBEX profile and receives 1 file. It is necessary to re-execute it to receive more files.
obex_get.sh:
Code:
#!/system/bin/sh
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
Failed*)
# bt disabled
echo "Please, enable bluetooth first!"
exit
;;
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH
;;
*)
# bt enabled, opush enabled
;;
esac
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
cd /sdcard/bluetooth_downloads && obexserver
EDIT: Daemonized version of the script. It can be run as service at boot time, and every 3 seconds it will check if the opush profile has been lost.
Code:
#!/system/bin/sh
# create the download directory if it doesn't exist
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
while sleep 3; do
# get bluetooth status
hcid_status_now="`getprop init.svc.hcid`"
# do nothing if bluetooth is stopped
test "$hcid_status_now" == "stopped" && continue
# if bluetooth is enabled, get opush profile status
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH; echo
;;
Failed*)
# bt disabled
#echo "Please, enable bluetooth first!"; echo
continue
;;
*)
# bt enabled, opush enabled
;;
esac
# if obexserver isn't already running, execute it.
pidof obexserver >/dev/null || ( cd /sdcard/bluetooth_downloads && obexserver ) &
done
EDIT: Ok, a definitely better version of the daemon:
Code:
#!/system/bin/sh
# create the download directory if it doesn't exist
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
# in case /sdcard/bluetooth_downloads already exists, and is not a directory. Exit
test -d /sdcard/bluetooth_downloads || exit
# execute the obexserver loop (for it to be multifile)
( cd /sdcard/bluetooth_downloads && while true; do obexserver; done ) &
# execute the sdptool add OPUSH loop
while sleep 3; do
# get bluetooth status
hcid_status_now="`getprop init.svc.hcid`"
# do nothing if bluetooth is stopped
test "$hcid_status_now" == "stopped" && continue
# if bluetooth is enabled and no obex profile exists, add it
sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push" >/dev/null || sdptool add --channel=4 OPUSH
done
Still don't like to query the "sdptool browse local" every 3 seconds
Bugs and corrections are welcome.
juanmasg said:
Ok, I didn't like to open a new thread about OBEX and android, but, as I explain in this post http://forum.xda-developers.com/showpost.php?p=3932525&postcount=57 , I got OBEX working in my G1, and now I'm thinking about integrating a clean and elegant OBEX support into our ROMS.
Yes, there is already an application in the market for receiving and sending files via OBEX, but I simply don't like to pay for a feature that should be supported by default in every mobile phone.
I was wondering how would be the first approach for integrating the obexserver by default, and it would be really easy executing at boot time something like:
Code:
sdptool add --channel=4 OPUSH
test -d /sdcard/bluetooth_received || mkdir /sdcard/bluetooth_received
cd /sdcard/bluetooth_received && ( while true; do obexserver; done ) &
The only problem, is that disabling bluetooth and enabling it again, it loses the OPUSH service added by sdptool.
So, I'm now trying to find a way to say the bluetooth daemons that they should add the OPUSH service when they are enabled, and here is where I need your help. Anybody knows how can this be done?
Also, another way would be simply executing a GScript when the OPUSH service is needed.
What do you think?
Thanks!
Click to expand...
Click to collapse
I am not really sure how the bluetooth stack works, but does the OPUSH profile has its own process or it there someway to detect its presence?
If so we could easily implement some detecting mechanism in the loop body.
Another possibility is to check the error returned by obexserver if it implements any.
im gonna check out the source tree for you, cause i was just looking last night. i will post again as a read into the source a lot more
billc.cn said:
I am not really sure how the bluetooth stack works, but does the OPUSH profile has its own process or it there someway to detect its presence?
If so we could easily implement some detecting mechanism in the loop body.
Another possibility is to check the error returned by obexserver if it implements any.
Click to expand...
Click to collapse
The obex profile does not have it's own process, sdptool simply enables it in one of the bluez daemons (don't know which of them)
The "problem" here is that obexserver does not get any error when I disable bluetooth, it simply continues waiting for a connection. I'll try to look at the openobex API to see if we can get the bluetooth status or force some error. Sorry, my knowledgement about the bluetooth protocol is quite limited.
The curious thing about this, is that if I execute obexserver, disable bt, re-enable bt, and add the opush profile, without restarting the obexserver it still works.
juanmasg said:
The obex profile does not have it's own process, sdptool simply enables it in one of the bluez daemons (don't know which of them)
The "problem" here is that obexserver does not get any error when I disable bluetooth, it simply continues waiting for a connection. I'll try to look at the openobex API to see if we can get the bluetooth status or force some error. Sorry, my knowledgement about the bluetooth protocol is quite limited.
The curious thing about this, is that if I execute obexserver, disable bt, re-enable bt, and add the opush profile, without restarting the obexserver it still works.
Click to expand...
Click to collapse
so maybe this is running on a seperate process? no its entirely own, but maybe a child process? seems kinda weird to me... and its gonna be a while before i can start checking this out along with you, i need to re-download the android repo >.<
As long as you have that script that has to be run every time you want 1 file, would it be possible to do that every, say, 3 seconds in a loop? Maybe even have an obex app where you can press a button to have the script start running the loop and press again to kill the process. I'm thinking something similar to the wifi tether for root users in terms of interface.
EDIT: so something similar to this in terms of scriptage(can't remember the exact syntax for loops)
Code:
while 1
do
#!/system/bin/sh
obex_status=`sdptool browse local 2>&1| egrep "^Service Name: OBEX Object Push|^Failed to connect"`
case "$obex_status" in
Failed*)
# bt disabled
echo "Please, enable bluetooth first!"
exit
;;
"")
# bt enabled, but no OPUSH profile
sdptool add --channel=4 OPUSH
;;
*)
# bt enabled, opush enabled
;;
esac
test -d /sdcard/bluetooth_downloads || mkdir /sdcard/bluetooth_downloads
cd /sdcard/bluetooth_downloads && obexserver
sleep 3;
done;
corp769 said:
so maybe this is running on a seperate process? no its entirely own, but maybe a child process? seems kinda weird to me...
Click to expand...
Click to collapse
I think that we shouldn't monitor the obex profile status, but spawn the profile activation when bluetooth gets active. This will be more efficient.
We can monitor the bluetooth status with "getprop init.svc.hcid". This could be used in the script loop, but it would save a lot of work if we simply could (de)activate it when the bluetooth gets enabled or disabled.
I'm looking at /etc/bluez in the G1 and in my linux desktop to see if some file could do the magic.
i need to re-download the android repo
Click to expand...
Click to collapse
be patient my friend
Can't you just do this from init with the other daemons?
service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
...etc
haha, i have no patience man, i'm in the military, and patience is not a virtue to me, i just want to get sh*t done
as far as what you are talking about, i understand what you mean. i'm also looking at the obex source in my linux distro (fedora 10) and kinda pondering if we could write a completely new routine (as a script for now of course) that would only be called when we need it, as in running it at boot and run in the background constantly. that hopefully wouldn't run up the processor tho...
and by the way, i would really like to help in everyway because i always wanted bluetooth file transfer on my G1
cyanogen said:
Can't you just do this from init with the other daemons?
service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
...etc
Click to expand...
Click to collapse
Already tried that, but didn't work . Those "services" seem to be requested by the a2dp daemon when it starts, and the a2dp daemon starts and stops when bluetooth is enabled or disabled, so we still would need to get our daemon spawned with all the bluetooth stuff.
Thanks anyways.
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
Thanks cyanogen, that is what I was looking for.
I wanted to avoid to recompile the android core server, but It seems that we'll have to :-/.
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
Exactly. Let's add the opush service here...
I'd love to patch it into my next ROM release
I added to the first post a modified version of the script that can be run as a "daemon".
Anyway, the way to implement this seems to be patching BluetoothDeviceService.java.
cyanogen said:
I'd love to patch it into my next ROM release
Click to expand...
Click to collapse
Can't wait for it
As for sending files, I was thinking about creating a mime handler that could be used with, p.e Filer (http://android.hlidskialf.com/software/filer) so that it could be able to send files via OBEX also.
Any idea?
cyanogen said:
BluetoothDeviceService.java does the work, would be trivial to patch this in..
Code:
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
//TODO: Don't assume HSP/HFP is running, don't use sdptool,
if (isEnabled()) {
SystemService.start("hsag");
SystemService.start("hfag");
}
break;
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
}
}
};
Click to expand...
Click to collapse
The more I think about it, the more I feel, that it should be done in ObexServer initialisation (ObexServer.java) ... which should be started from BluetoothDeviceService
here is my question... ok, we have the obex server for receiving files. now as far as sending files, how will that be set up? like will it be a seperate script to run the program, or will it be combined with the obex server?
an idea or two... juan, you mentioned about setting up a mime handler to send files. what it be possible to set up the handler for both receiving and sending files? it could most definitely be accomplished by creating a whole separate APK, and have that register the handles for the system, running as a service in the background. also we could use that for a graphical interface in the long run after we get the basics down pat, and have a file browser for sending files. i know this is jumping the gun, but it is all my ideas i have going on. on that note though, i think it would be the best way, unless you have a better idea
EDIT: now that i think of it, the APK would be best off other wise so we wouldnt have to have everyone who wants file transfer to reflash their whole phone just for a partially modified kernel
corp769 said:
EDIT: now that i think of it, the APK would be best off other wise so we wouldnt have to have everyone who wants file transfer to reflash their whole phone just for a partially modified kernel
Click to expand...
Click to collapse
I'd rather make part of the framework ready to be accepted by the AOSP than some kind of hack running only on rooted devices. Which brings another question: I was just starting to port the obexserver, when I realized that the OpenOBEX library is licensed under LGPL ... can we use it?
I've been trying all day to get my Huawei Ascend android phone to use Cricket's WAP proxy for apps like android marketplace, but it never seems to work. I still get some error stating that Data Connection is not working or has timed-out. All that works is the Browser and Cricket's built-in apps, though they worked before I was using the autostart.sh file anyways.
I tried different variations on the code and none of them seem to work.
This is the current code I have for my auotstart.sh file.
Code:
#!/system/bin/sh
export PROXYHOST=wap.mycricket.com
export PROXYPORT=8080
export MMSHOST=mms.mycricket.com
export MMSPORT=80
#you shouldn't have to edit anything below this line
export PATH="$PATH:/system/bin"
until netcfg|grep -v DOWN|awk '{print $1}'|grep -v wlan|grep -v lo >/dev/null 2>&1 ; do sleep 1 ; done
export INTERFACE=`netcfg|grep -v DOWN|awk '{print $1}'|grep -v wlan|grep -v lo`
export PROXYIP=`ping -c 1 $PROXYHOST|grep PING|cut -d\) -f1|cut -d\( -f2`
export MMSIP=`ping -c 1 $MMSHOST|grep PING|cut -d\) -f1|cut -d\( -f2`
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -A OUTPUT -o $INTERFACE -p tcp -d $MMSIP --dport $MMSPORT -j DNAT --to-destination $MMSIP:$MMSPORT
iptables -t nat -A OUTPUT -o $INTERFACE -p tcp --dport 80 -j DNAT --to-destination $PROXYIP:$PROXYPORT
iptables -t nat -A OUTPUT -o $INTERFACE -p tcp ! -d $PROXYIP -j REDIRECT --to-port 1025
u2nl $PROXYIP $PROXYPORT 127.0.0.1 1025 >/dev/null 2>&1 &
sh -c "sleep 5;kill `ps|grep nk.bla.android.autostart|grep -v grep|awk '{print $2}'`" >/dev/null 2>&1 &
exit 0
Is that any way to get it working?
ummm, why are you doing it that way? If you have the Android plan, all you need to do is set-up the APN if it's not working.
xlarkascendingx said:
ummm, why are you doing it that way? If you have the Android plan, all you need to do is set-up the APN if it's not working.
Click to expand...
Click to collapse
I'm not on the Android plan, so I need to use autostart.sh to get apps to work with cricket's WAP Proxy.
That sucks, why don't you just get the android plan haha.
xlarkascendingx said:
That sucks, why don't you just get the android plan haha.
Click to expand...
Click to collapse
Because I don't have $55 a month. DO you wanna give me $55/month?
Just suck it up, pay the extra $10, or continue to have problems. Your choice.
Well you obviously have 45 dollars a month, otherwise you wouldn't have internet period. It's really not that big of a difference in price. Plus, you paid for the phone lol.
tzbigworm said:
Just suck it up, pay the extra $10, or continue to have problems. Your choice.
Click to expand...
Click to collapse
How about giving a real answer to my question or not posting in this thread at all.
xlarkascendingx said:
Well you obviously have 45 dollars a month, otherwise you wouldn't have internet period. It's really not that big of a difference in price. Plus, you paid for the phone lol.
Click to expand...
Click to collapse
Well, actually the plan is much cheaper than that, lol.
I'm not sure how I'm getting Internet, but since I am getting it I'm going to use it.
try changing the ports to 8080, where it says tcp in the section you may not have to edit or whatever. i always use 8080
xlarkascendingx said:
try changing the ports to 8080, where it says tcp in the section you may not have to edit or whatever. i always use 8080
Click to expand...
Click to collapse
I tried that, but it still didn't work.
Did this problem ever get resolved?
Hi All,
I have a stupid Juniper VPN device at work which does not support 64 bit linux clients using netconnect. I have found ways around this previously, but now we are setting up 2 factor auth which throws a lot of javascript into the mix, making the scripts I used pretty much obsolete. The Junos pulse client works well for android, so I am thinking I want to use an android device as a router. Connecting to the VPN and using wifi tethering does not work, same with USB tethering does not work, and those are not exactly what I want anyway.
So basically I want to be able to connect my android device to my wifi here at home, connect to the VPN on it, run a script to do my setup on the Android device, lastly add a route on my client pc to tunnel through the android device. here is what I tried so far on the device:
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
iptables -P FORWARD ACCEPT
iptables -t nat -I POSTROUTING -s 192.168.0.0/16 -d 10.0.0.0/8 -j MASQUERADE
ip rule add from all to 10.0.0.0/8 fwmark 0x3c lookup 60
and on the client PC:
Code:
route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.29
where 192.168.1.29 is the IP of my android device, and 10.0.0.0/8(I know its lazy) is the IP range I want to go through tun0 on the device. This is however not working.
The only thing I need to do on a standard linux box to do this would be:
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -I POSTROUTING -s 192.168.0.0/16 -d 10.0.0.0/8 -j MASQUERADE
And setup the same route command on the client but point it at the linux box instead. This currently works, but when we decide to flip the switch and use the 2 factor auth only I will not be able to make it work on a standard linux box, but 2 factor does work on android via the Junos app.
I fear I am missing something simple in Android land, please help...