[Q] init.rc - disable usb connection - Galaxy Tab 2 Q&A, Help & Troubleshooting

All,
I am attempting to block all forms of USB connection via a PC when the tab is plugged in (long reason why - but security requirement for my organisation).
So my first call was to look around the Kernel init.rc files to find out where the USB was activated, and it appears that init.rc calls init.espresso.usb.rc.
Commenting out the include file, building a new boot.img and flashing the device prevents USB access to the PC, but it also has the side effect of disabling the WiFi...
This is the content of the file ... so my question is - which bits of this are responsible for WiFi? I assume rndis - but i thought that was just tethering?
What should be being loaded to make WiFi work? Or are there any better ways of achieving my goals of blocking usb file acces, adb tethering etc...?
Code:
on init
write /sys/class/android_usb/android0/iSerial $ro.serialno
write /sys/class/android_usb/android0/f_rndis/manufacturer Samsung
write /sys/class/android_usb/android0/f_rndis/vendorID 04e8
write /sys/class/android_usb/android0/f_rndis/wceis 1
on boot
write /sys/class/android_usb/android0/iManufacturer $ro.product.manufacturer
write /sys/class/android_usb/android0/iProduct $ro.product.model
on property:sys.usb.config=mtp
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6860
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=mtp,adb
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6860
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/enable 1
start adbd
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=rndis
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6863
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/bDeviceClass 224
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=rndis,adb
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6864
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/bDeviceClass 224
write /sys/class/android_usb/android0/enable 1
start adbd
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=ptp
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6865
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=ptp,adb
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6866
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/enable 1
start adbd
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=rndis,dm
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 04e8
write /sys/class/android_usb/android0/idProduct 6862
write /sys/class/android_usb/android0/functions $sys.usb.config
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state $sys.usb.config

Do not comment out the included file but change all "enable 1" to "enable 0".

ketut.kumajaya said:
Do not comment out the included file but change all "enable 1" to "enable 0".
Click to expand...
Click to collapse
Ok - so it turns out i was making a school boy error, the Version Magic on the Kernel wasn't matching the dhd.ko WiFi module. Looks like I didn't test that part before moving on!
Live and learn!
However - the method i was using i.e. Not calling init.<device>.usb.config.rc appears to work if anyone else needs to disable USB for security purposes.

Related

[Q] 4.3 update (touchwiz) - no codes work anymore - how do I QPST now?

original firmware had a number of hidden codes that you put into dialer and it does stuff. None of them work anymore. Particularly the ones I care about are:
*#22745927 to enable hidden menu.
*#7284# to switch the UART and USB from PDA to MODEM (so that I could program PRL with QPST)
*#0*# hardware test
Are there alternatives?..
No.
Sent from my Last Ever Samsung Device.
0331 said:
No.
Sent from my Last Ever Samsung Device.
Click to expand...
Click to collapse
On the older firmwares there was an IOTHiddenMenu activity which you could invoke using
Code:
am start com.android.hiddenmenu/com.android.hiddenmenu.IOTHiddenMenu
command, but that doesn't work on 4.3
I know in AOSP there was a notion to turn into QPST mode by writing to kernel pseudo-files...
Engineers got to somehow be able to reprogram these phones, there's no way Samsung disabled this completely
I dug out some old scripts for AOSP, which seem to work. Device was accessible in QPST-programmable mode after them:
Code:
#/system/bin/sh
# sets DIAG mode
echo 0 > /sys/class/android_usb/android0/enable
echo 04E8 > /sys/class/android_usb/android0/idVendor
echo 6860 > /sys/class/android_usb/android0/idProduct
echo diag > /sys/class/android_usb/android0/f_diag/clients
echo 1 > /sys/class/android_usb/android0/f_acm/instances
echo diag,acm,adb > /sys/class/android_usb/android0/functions
cat /sys/class/android_usb/android0/functions
echo 1 > /sys/class/android_usb/android0/enable
start adbd
setprop sys.usb.state sys.usb.config
and to go back to MTP:
Code:
#/system/bin/sh
# sets default USB mode
echo 0 > /sys/class/android_usb/android0/enable
echo 04E8 > /sys/class/android_usb/android0/idVendor
echo 6860 > /sys/class/android_usb/android0/idProduct
echo 1 > /sys/class/android_usb/android0/f_acm/instances
echo mtp,acm,adb > /sys/class/android_usb/android0/functions
echo 1 > /sys/class/android_usb/android0/enable
start adbd
setprop sys.usb.state sys.usb.config

USb tethering lags - fix enhancement

Hi everyone!
Sorry for the long post, but I wanted to be clear
I've just read a recent post concerning USB tethering lags under windows 8.1:
http://forum.xda-developers.com/android/general/fix-usb-tethering-lags-freezes-windows-t3039183
All in all, to fix the issue, I have to force the installation of another driver (which is called "Remote NDIS Compatible Device") instead of the windows stock one (called "Remote NDIS based Internet Sharing Device"). After the operation, the lags disappeared.
Now, what i would like to do is modify the usb device descriptor given by android when tethering is activated to tell windows to directly install the right driver. According to the inf file of "Remote NDIS Compatible Device", named rndiscmp.inf, any usb hardware with the following spec will trigger the driver install:
DeviceClass=EF
DeviceSubClass=04
DeviceProtocol=01
Now there is an rc file in / called init.qcom.usb.rc on my device telling what parameters to give to the usb when usb tethering is enabled. The interesting part is here:
Code:
on property:sys.usb.config=rndis
write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor 05C6
write /sys/class/android_usb/android0/idProduct 676A
write /sys/class/android_usb/android0/functions rndis
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state ${sys.usb.config}
So I went to /sys/class/android_usb/android0/ and it seems this is the place where the usb device descriptor is set. There are 3 interesting files:
bDeviceClass
bDeviceSubClass
bDeviceProtocol
So to make the modification, I added in the rc file before the "enable 1":
Code:
write /sys/class/android_usb/android0/idProduct 676E
write /sys/class/android_usb/android0/bDeviceClass EF
write /sys/class/android_usb/android0/bDeviceSubClass 04
write /sys/class/android_usb/android0/bDeviceProtocol 01
(I changed the idProduct to see if it would change in windows when I would plug the device).
I rebuilt the boot.img with these modifications (since / is a ramdisk and the rc file is extracted from the boot image at each startup), flashed it to my phone (with fastboot flash boot boot.img) and hoped that when enabling the usb tether option, I would see the new idProduct and the new class, subclass and protocol of the device, and with the right driver!
When plugging it on windows, and enabling usb tethering, the idProduct changed as expected, but the class, subclass and protocol were the same than before (FYI: E0,01,03), therefore triggering the bad driver install (whose inf is named WceISVista.inf by the way). I went to /sys/class/android_usb/android0/ and checked each three files I asked to be modified:
cat bDeviceClass : 0
cat bDeviceSubClass : 4
cat bDeviceProtocol : 1
Why would the bDeviceClass be set back to 0?
I feel I'm so close, would you guys have any ideas? Thank you!

Run stop Zygote script on Android

Hello all. I need to stop Zygote and make script something like this:
Code:
setprop ctl.stop media
setprop ctl.stop zygote
setprop ctl.stop bootanim
sleep 1
setprop ctl.start bootanim
setprop ctl.start media
setprop ctl.start zygote
sleep 1
exit 0
How can i do this on Android without ADB. The main goal is to make programm that can start by user. Can anyone help any idea.
One fix i need to do some monipulations with file system when Zygote stop. May be something with ADB or i think wrong way?

Porting CM to new device, adb won't start by itself

Hi,
I've started porting CM10 (old) to Galaxy Fame Lite (old and cheap phone). The phone starts but remains stuck at the boot animation. The problem is that I had to modify the configuration to have 1) adb capability exposed and 2) start adbd.
Without modification, the phone is not listed by adb (kill-server/start-server done, drivers updated). One of the problem is that property sys.usb.config=mtp. When I apply the following:
Code:
diff --git a/rootdir/init.bcm2165x.usb.rc b/rootdir/init.bcm2165x.usb.rc
index 02a6295..b729ad9 100644
--- a/rootdir/init.bcm2165x.usb.rc
+++ b/rootdir/init.bcm2165x.usb.rc
@@ -76,9 +76,10 @@ on property:sys.usb.config=mtp
write /sys/class/android_usb/android0/bDeviceClass EF
write /sys/class/android_usb/android0/bDeviceSubClass 02
write /sys/class/android_usb/android0/bDeviceProtocol 01
- write /sys/class/android_usb/android0/functions mtp,acm
+ write /sys/class/android_usb/android0/functions mtp,acm,adb
write /sys/class/android_usb/android0/f_acm/instances 2
write /sys/class/android_usb/android0/enable 1
+ start adbd
setprop sys.usb.state $sys.usb.config
on property:sys.usb.config=mtp,adb
the phone is listed by adb, which is better, but "offline". I need to remove "disabled" in "service adbd" stanza of init.rc to have working adb.
It works, but it's not very nice... What should I do to have working adbd right from the first seconds?
Thanks!

Set MTP as default for USB on Android 7.1.2 / LineageOS 14.1 on SM-T280

Hey,
I'm running LineageOS 14.1 (Android 7.1.2) on an SM-T280. It's also rooted.
Whenever I reboot and connect USB, it only enables adb and charges. I want it to enable adb and mtp by default.
I know about the setting in the developer options, but this also is not persistent.
How do I enable MTP by default?
In Android's system file build.prop add MTP as default USB-mode
Code:
persist.sys.usb.config=mtp,adb
xXx yYy said:
In Android's system file build.prop add MTP as default USB-mode
Code:
persist.sys.usb.config=mtp,adb
Click to expand...
Click to collapse
Tried, does not work. When I reboot I get this:
Code:
gtexswifi:/ # cat /system/build.prop | grep usb
persist.sys.usb.config=mtp,adb
sys.usb.gser.count=8
sys.usb.config=mtp,adb
persist.sys.usb.config=mtp,adb
sys.usb.configfs=1
gtexswifi:/ # getprop | grep usb
[persist.sys.usb.config]: [adb]
[sys.usb.config]: [adb]
[sys.usb.configfs]: [0]
[sys.usb.ffs.ready]: [1]
[sys.usb.gser.count]: [8]
[sys.usb.state]: [adb]
gtexswifi:/ # ls /data/property/ | grep usb
persist.sys.usb.config
gtexswifi:/ # cat /data/property/persist.sys.usb.config
adb
Of course I also tried setprop persist.sys.usb.config "mtp,adb" which modifies /data/property/persist.sys.usb.config but this is reset on reboot.
I've found many websites that say it is simply not possible on Nougat :/
I also found https://forum.xda-developers.com/t/app-root-r-3-3-marshmallow-mtp-enabler.3263467/ but I don't want to install an app :/ I'm curious how it does it.
When I setprop sys.usb.config "mtp,adb" while the device is running, usb disconnects and reconnects, but there is still no MTP available.
Also tried
Bash:
echo 0 > /sys/class/android_usb/android0/enable
echo mtp,adb > /sys/class/android_usb/android0/functions
echo 1 > /sys/class/android_usb/android0/enable
The device disconnects and reconnects from USB but only with adb enabled and
Code:
gtexswifi:/ # cat /sys/class/android_usb/android0/functions
ffs
afterwards
Source: https://books.google.de/books?id=0cuQAwAAQBAJ&pg=PA64&lpg=PA64&dq="android_usb/android0/enable"+mtp
Okay, I wen't through the effort to recompile the kernel and patch the init ramdisks /default.prop with
Code:
persist.sys.usb.config=adb,mtp
sys.usb.config=adb,mtp
Didn't help...
Any other ideas?

Categories

Resources