Android - FritzBox VPN - General Questions and Answers

Hello,
i would like to connect my desire with vpn to my fritzxbox.
can someone help me?
what do i have to choose?
L2TP-VPN
L2TP/IPSec PSK-VPN
L2TP/IPSec CRT-VPN
i have this two files vpnuser.cfg and vpnuser.vpn
there should be all necessitate data but don't know what to take.
cpnuser.vpn
Code:
n:version:3
n:network-ike-port:500
n:network-mtu-size:1380
n:client-addr-auto:1
n:network-natt-port:4500
n:network-natt-rate:15
n:network-frag-size:540
n:network-dpd-enable:1
n:client-banner-enable:1
n:network-notify-enable:1
n:client-dns-used:0
n:client-dns-auto:1
n:client-dns-suffix-auto:1
n:client-splitdns-used:1
n:client-splitdns-auto:0
n:client-wins-used:0
n:client-wins-auto:1
n:phase1-dhgroup:2
n:phase1-keylen:256
n:phase1-life-secs:86400
n:phase1-life-kbytes:0
n:vendor-chkpt-enable:0
n:phase2-keylen:256
n:phase2-life-secs:3600
n:phase2-life-kbytes:0
n:policy-nailed:0
n:policy-list-auto:0
s:network-host:dyndns
s:client-auto-mode:pull
s:client-iface:virtual
s:network-natt-mode:enable
s:network-frag-mode:enable
s:auth-method:mutual-psk
s:ident-client-type:ufqdn
s:ident-server-type:address
s:ident-client-data:myusername
b:auth-mutual-psk:long_code
s:phase1-exchange:aggressive
s:phase1-cipher:aes
s:phase1-hash:sha1
s:phase2-transform:esp-aes
s:phase2-hmac:sha1
s:ipcomp-transform:deflate
n:phase2-pfsgroup:2
s:policy-list-include:192.168.178.0 / 255.255.255.0
vpnuser.cfg
Code:
/*
* C:\Users\myname\AppData\Roaming\AVM\FRITZ!Fernzugang\dyndns\user\vpnuser.cfg
* Tue Feb 16 11:18:33 2010
*/
version {
revision = "$Revision: 1.30 $";
creatversion = "1.1";
}
pwcheck {
}
datapipecfg {
security = dpsec_quiet;
icmp {
ignore_echo_requests = no;
destunreach_rate {
burstfactor = 6;
timeout = 1;
}
timeexceeded_rate {
burstfactor = 6;
timeout = 1;
}
echoreply_rate {
burstfactor = 6;
timeout = 1;
}
}
masqtimeouts {
tcp = 15m;
tcp_fin = 2m;
tcp_rst = 3s;
udp = 5m;
icmp = 30s;
got_icmp_error = 15s;
any = 5m;
tcp_connect = 6m;
tcp_listen = 2m;
}
ipfwlow {
input {
}
output {
}
}
ipfwhigh {
input {
}
output {
}
}
NAT_T_keepalive_interval = 20;
}
targets {
policies {
name = "mydyn.dns";
connect_on_channelup = no;
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
virtualip = 192.168.178.201;
remoteip = 0.0.0.0;
remotehostname = "mydyn.dns";
localid {
user_fqdn = "username";
}
mode = mode_aggressive;
phase1ss = "all/all/all";
keytype = keytype_pre_shared;
key = "long code";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = no;
use_cfgmode = no;
phase2localid {
ipaddr = 192.168.178.201;
}
phase2remoteid {
ipnet {
ipaddr = 192.168.178.0;
mask = 255.255.255.0;
}
}
phase2ss = "esp-all-all/ah-none/comp-all/pfs";
accesslist = "permit ip any 192.168.178.0 255.255.255.0";
wakeupremote = no;
}
}
policybindings {
}
// EOF
can someone help me? thanks in advance

..any updates on this ?
I'm facing the same problem
,Wolfgang

never seen anything like that

this may help you
show post#775248 there is a solution for vpnc and fritzbox

mp1405 said:
show post#775248 there is a solution for vpnc and fritzbox
Click to expand...
Click to collapse
Where is this post#775248?

Hello there,
1. It is necessary that your device is rooted.
2. In order to connect via Fritz!VPN you need to use VPNC Widget. If "check prerequisites" states that it should work you are good to go.
3. The config file for FritzBox needs to look like this in order to work with Android devices. You need to change the UPPERCASE values *and IF changed from the 192.168.178.X default also change IP settings* afterwards enter these values in VPNC Widget and it should work.
/*
/*
*C:\Users\tom\AppData\Roaming\AVM\FRITZ!Fernzugang\fritzbox_avmvpn_dyndns_org.cfg
* Mon Mar 07 17:49:59 2011
*/
vpncfg {
connections {
enabled = yes;
conn_type = conntype_user;
name = "NAMEINFRITZGUI";
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
local_virtualip = 0.0.0.0;
remoteip = 0.0.0.0;
remote_virtualip = 192.168.100.201;
remoteid {
key_id = "USER";
}
mode = phase1_mode_aggressive;
phase1ss = "all/all/all";
keytype = connkeytype_pre_shared;
key = "PASSWORD";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = yes;
use_cfgmode = no;
xauth {
valid = yes;
username = "USER1";
passwd = "PASSWORT1";
}
phase2localid {
ipnet {
ipaddr = 0.0.0.0;
mask = 0.0.0.0;
}
}
phase2remoteid {
ipaddr = 192.168.100.201;
}
phase2ss = "esp-all-all/ah-none/comp-all/no-pfs";
accesslist = "permit ip 0.0.0.0 0.0.0.0 192.168.100.201 255.255.255.255";
}
ike_forward_rules = "udp 0.0.0.0:500 0.0.0.0:500",
"udp 0.0.0.0:4500 0.0.0.0:4500";
}
// EOF
Click to expand...
Click to collapse
Greetings
Geniac

@geniac
Thank you

Hello all ...
I'd like to connect my HTC1s via VPN to my Fritzbox 3170.
The connection works, I have access to my homenetwork and a small bandwidth to check my emails, but when I start the browser or speedtest there's no connection.
I use cm9 alpha14 and I tried VPNC Widget and vpncilla as well as onboard vpn.
Do I have to make further modifications to my Fritzbox?
for the cfg - file I used the code posted by geniac
thanks 4 ur help
greetz
Tomcatz

Related

source code of StartMenuRebuilder (small stuff for A.I.)

Finally,I have successfully get my PC online,before today only one computer - my friend's PC can online,the lessor of house only provided a port and bind MAC address.
Code:
/*
Author:xiaojin1985[小金]
Version:1.2
Updates:
+ Directories can be removed now.
*/
// StartMenuRebuilder.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
BOOL IsFileExist(LPCTSTR lpFileName){
WIN32_FIND_DATA m_data;
HANDLE hFile;
BOOL bFileFound = FALSE;
hFile=FindFirstFile(lpFileName,&m_data);
if(hFile==INVALID_HANDLE_VALUE){
bFileFound = FALSE;
}else{
bFileFound = TRUE;
}
FindClose(hFile);
return bFileFound;
}
BOOL SearchDir(PCTSTR ptzSrc)
{
WIN32_FIND_DATA fd;
TCHAR tzSrc[MAX_PATH];
TCHAR tzFind[MAX_PATH];
wsprintf(tzFind, TEXT("%s\\*"), ptzSrc);
HANDLE hFind = FindFirstFile(tzFind, &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (fd.cFileName[0] != '.')
{
wsprintf(tzSrc, TEXT("%s\\%s"), ptzSrc, fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
SearchDir(tzSrc);
}
else
{
//_debug(L"%s",tzSrc);
SetFileAttributes(tzSrc,FILE_ATTRIBUTE_NORMAL);
DeleteFile(tzSrc);
}
}
}
while (FindNextFile(hFind, &fd));
FindClose(hFind);
RemoveDirectory(ptzSrc);
}
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szPath[MAX_PATH];
wchar_t szFileExec[256] = _T("");
wchar_t WorkPath[255];//工作路径
int i;
GetModuleFileName(NULL,WorkPath,255);
i = wcslen(WorkPath)-1;
for(;WorkPath[i]!='\\';i--);
WorkPath[i+1]='\0';
wsprintf(szFileExec,TEXT("%sStartMenu.cab"),WorkPath);
if(IsFileExist(szFileExec)){
SHGetSpecialFolderPath(NULL, szPath, CSIDL_STARTMENU, FALSE);
SearchDir(szPath);
//If you want run it independence,plz remove the comment lines.
/*
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
wchar_t szFileArgv[256] = _T("");
wsprintf(szFileArgv,TEXT("/nodelete /noui /silent %s"),szFileExec);
//_debug(L"%s",szFileArgv);
CreateProcess(TEXT("wceload.exe"),szFileArgv,0,0,0,0,0,0,&si,&pi);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);*/
}else{
MessageBox(NULL,L"StartMenu.cab NOT FOUND!",L"Rebuilder by xiaojin",MB_OK);
}
return 0;
}
ha ha ha ha ha ha
source code of StartMenuRebuilder (small stuff for A.I.)
You're talking about something?

browser crash possibly related to invalid SSL certificate

Hey guys,
Have you ever had problem logging on a SSL certificate network?? An example is the cisco authentication on the wifi ( like my college has ). Well looking around I found this solution posted by dalvik.
http://code.google.com/p/android/issues/detail?id=1597#c18
This certainly is something that will be released on source.android.com (aka aosp)
when the Froyo code is released. In the meanwhile, I tryed to explain the change so
that people making custom ROMs could feel free to fix it. To be more explicit, here
is the exact diff:
diff --git a/core/java/android/net/http/SslCertificate.java
b/core/java/android/net/http/SslCertificate.java
index 46b2bee..2214405 100644
--- a/core/java/android/net/http/SslCertificate.java
+++ b/core/java/android/net/http/SslCertificate.java
@@ -196,26 +196,31 @@ public class SslCertificate {
*/
public DName(String dName) {
if (dName != null) {
- X509Name x509Name = new X509Name(mDName = dName);
-
- Vector val = x509Name.getValues();
- Vector oid = x509Name.getOIDs();
-
- for (int i = 0; i < oid.size(); i++) {
- if (oid.elementAt(i).equals(X509Name.CN)) {
- mCName = (String) val.elementAt(i);
- continue;
- }
-
- if (oid.elementAt(i).equals(X509Name.O)) {
- mOName = (String) val.elementAt(i);
- continue;
- }
-
- if (oid.elementAt(i).equals(X509Name.OU)) {
- mUName = (String) val.elementAt(i);
- continue;
+ mDName = dName;
+ try {
+ X509Name x509Name = new X509Name(dName);
+
+ Vector val = x509Name.getValues();
+ Vector oid = x509Name.getOIDs();
+
+ for (int i = 0; i < oid.size(); i++) {
+ if (oid.elementAt(i).equals(X509Name.CN)) {
+ mCName = (String) val.elementAt(i);
+ continue;
+ }
+
+ if (oid.elementAt(i).equals(X509Name.O)) {
+ mOName = (String) val.elementAt(i);
+ continue;
+ }
+
+ if (oid.elementAt(i).equals(X509Name.OU)) {
+ mUName = (String) val.elementAt(i);
+ continue;
+ }
}
+ } catch (IllegalArgumentException ex) {
+ // thrown if there is an error parsing the string
}
}
}
I'm not a developer and I don't have idea how to implement this patch to the rom, but if anybody knows how, I'll be happy to test the rom.
Thanks
Christian

[Q] Stuck very badly

Code:
private static string Post(string url, string data)
{
System.Net.WebRequest request1 = WebRequest.Create(url);
request1.Method = "POST";
request1.ContentType = "application/json";
byte[] byteData = Encoding.UTF8.GetBytes(data);
request1.ContentLength = byteData.Length;
using (Stream s = request1.GetRequestStream())
{
s.Write(byteData, 0, byteData.Length);
s.Close();
}
string replyData;
using (HttpWebResponse response = (HttpWebResponse)request1.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
replyData = reader.ReadToEnd();
}
}
}
I am receiving an error on [request1.ContentLength] and using (Stream s = request1.GetRequestStream())
pls i really need assistance on this

[Completed] Trouble with string encode after decompile APK file

Hello,
I have a trouble with a string text encode after decompile an APK file.
I used APK Tool decompile. The origin file http_//file.9app.info/files/tuan/tuan2india/9-apps.apk
The code was encoded here:
Code:
public class API
extends Activity
{
public static String a = "081b11458016006d513b0290cc7be0b39c28626ea506b9ed291b125114f2a38369a42e77a066a7789e5883ed47113fc3";
public static String b = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static String c = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static JSONObject d = new JSONObject();
public static String e = "";
private static int h = 0;
private boolean f = false;
private ProgressDialog g;
private JSONObject a(JSONObject paramJSONObject)
{
int i = 0;
Iterator localIterator = paramJSONObject.keys();
int[] arrayOfInt = new int[paramJSONObject.length()];
int j = 0;
JSONObject localJSONObject1;
int m;
if (!localIterator.hasNext())
{
Arrays.sort(arrayOfInt);
localJSONObject1 = new JSONObject();
m = arrayOfInt.length;
}
for (;;)
{
if (i >= m)
{
return localJSONObject1;
int k = j + 1;
arrayOfInt[j] = Integer.parseInt(((String)localIterator.next()).toString());
j = k;
break;
}
String str1 = Integer.toString(arrayOfInt[i]);
try
{
JSONObject localJSONObject2 = (JSONObject)paramJSONObject.get(str1);
if (((paramJSONObject.get(str1) instanceof JSONObject)) && (!a(localJSONObject2.get("package").toString())))
{
String str2 = localJSONObject2.get("package").toString();
if (!getApplicationContext().getSharedPreferences("listpacks", 0).getBoolean(str2, false)) {
if (localJSONObject2.get("type").toString().equals("1"))
{
if (!this.f)
{
this.f = true;
d = localJSONObject2;
}
}
else
{
e = e + localJSONObject2.get("package").toString() + "|";
localJSONObject1.put(str1, localJSONObject2);
}
}
}
}
catch (JSONException localJSONException)
{
localJSONException.printStackTrace();
}
i++;
}
}
Anybody can help me decode 3 text string a,b,c please?
Hello,
Try posting your question in the forum linked below.
http://forum.xda-developers.com/android/help
The experts there may be able to help. Good luck.
Hello,
I'm newbie so I don't know where to post right. Thank you for your advice!

Cell Info 5G NR Neighbour Cells Information

Hi all,
I'm developing an application that captures the information of the LTE and 5G NR network information. I have created two different services (Kotlin services that are very similar to pool threads) which captures the information of the LTE and its neighbours in one service and the same for 5G NR in another service. The transformation to obtain the same information is very similar from LTE to 5G, and it is supposed to work. In the LTE service I obtain the information of the LTE serving cell information below (First quote) and the 5G NR service in the other quote. I would like to point out from the 5G service provides me the information of ONLY the serving cell, however, I need the information of all the cells. Does anyone have any clue?
Thanks for anyone who stops for reading this =)
package com.mobilenet.monitoring.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.Binder
import android.os.Handler
import android.os.IBinder
import android.telephony.*
import android.util.Log
import androidx.core.app.ActivityCompat
import com.mobilenet.monitoring.R
import com.mobilenet.monitoring.app.preferences
import org.json.JSONObject
import java.text.DateFormat
import java.util.*
import kotlin.collections.HashMap
class ServiceLte : Service() {
val TAG = "TESTING"
private var mBinder: IBinder = MyBinder()
private var mHandler = Handler()
/* Lte Parameters */
var mSignalStrength: SignalStrength? = null
var mListSignalStrength: List<CellSignalStrength>? = null
var mSignalStrengthLte: CellSignalStrengthLte? = null
var mManager: TelephonyManager? = null
/* LteConnection */
private var mLteData: JSONObject = JSONObject()
private var mLteNeighbourData: JSONObject = JSONObject()
var infos: MutableList<CellInfo>? = null
private lateinit var mContext:Context
private var jsonObject:JSONObject = JSONObject()
private var dataNeighbour = HashMap< String, String>()
private var lte:CellSignalStrengthLte? = null
private var identityLte:CellIdentityLte? = null
private var ci:Int = -1
private var MCC:String? = ""
private var MNC:String? = ""
private var PLMN:String? = ""
private var cellidHex: String = ""
private var eNBHex:String = ""
private var eNB: Int = -1
override fun onBind(intent: Intent): IBinder? {
return mBinder
}
@SuppressLint("MissingPermission")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate")
mContext = this
/* LTE */
mManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
//mManager!!.listen( mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS or PhoneStateListener.LISTEN_CELL_INFO)
update()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "onStartCommand")
if(intent?.getStringExtra("action") == "Destroy"){
onDestroy()
}
val CHANNELID = "Foreground Service ID"
val channel = NotificationChannel(
CHANNELID,
CHANNELID,
NotificationManager.IMPORTANCE_LOW
)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
val notification: Notification.Builder = Notification.Builder(this, CHANNELID)
.setContentText("Monitoring is running")
.setContentTitle("Monitoring enabled")
.setSmallIcon(R.drawable.ic_launcher_background)
startForeground(1001, notification.build())
return super.onStartCommand(intent, flags, startId)
}
fun getLteData(): JSONObject {
return mLteData
}
fun getNeighbourLteData(): JSONObject {
return mLteNeighbourData
}
// Listener for signal strength.
private val mListener: PhoneStateListener = object : PhoneStateListener() {
override fun onSignalStrengthsChanged(sStrength: SignalStrength) {
mSignalStrength = sStrength
Log.d(TAG,"SignalStrength cambia HOLAA")
if (ActivityCompat.checkSelfPermission(mContext,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
infos = mManager!!.allCellInfo
}
}
override fun onCellInfoChanged(cellInfo: MutableList<CellInfo>) {
Log.d(TAG,"CellInfo cambia")
infos = cellInfo
}
}
private fun update() {
val runnable = object : Runnable {
@SuppressLint("MissingPermission", "NewApi")
override fun run() {
mLteData = JSONObject()
mLteNeighbourData = JSONObject()
infos = null
jsonObject = JSONObject()
mManager!!.requestCellInfoUpdate( mContext.mainExecutor,
object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(cellInfo: MutableList<CellInfo>) {
Log.d(TAG, "Requesting cell update")
getData(cellInfo)
}
})
mHandler.postDelayed(this, 500)//preferences.periodicity.toLong())
}
}
mHandler.postDelayed(runnable, 500)//preferences.periodicity.toLong())
}
@SuppressLint("NewApi")
private fun getData(cellInfo: MutableList<CellInfo>){
try {
mSignalStrengthLte = (cellInfo[0] as CellInfoLte).cellSignalStrength
//LTE connected
if (preferences.LteEnable) {
if (preferences.LteCQI) mLteData.put("LteCqi", "${mSignalStrengthLte!!.cqi}")
if (preferences.LteLevel) mLteData.put("LteLevel","${mSignalStrengthLte!!.level}")
if (preferences.LteRSRP) mLteData.put("LteRSRP", "${mSignalStrengthLte!!.rsrp}")
if (preferences.LteRSRQ) mLteData.put("LteRSRQ", "${mSignalStrengthLte!!.rsrq}")
if (preferences.LteRSSI) mLteData.put("LteRSSI", "${mSignalStrengthLte!!.rssi}")
if (preferences.LteRSSNR) mLteData.put("LteRSSNR","${mSignalStrengthLte!!.rssnr}")
if (preferences.LteTA) mLteData.put("LteTimingAdvance", "${mSignalStrengthLte!!.timingAdvance}")
if (preferences.LteDbm) mLteData.put("LteDbm", "${mSignalStrengthLte!!.dbm}")
if (preferences.LteAsuLevel) mLteData.put("LteAsuLevel", "${mSignalStrengthLte!!.asuLevel}")
}
}catch (ex: Exception) {
Log.i(TAG, ex.message)
}
//LTE neighbours
@SuppressLint("MissingPermission")
infos = mManager!!.allCellInfo
jsonObject = JSONObject()
dataNeighbour = HashMap< String, String>()
if (preferences.NeighbourLteEnable){
jsonObject.put("NumberOfSites", "${infos!!.size}")
}
for (i in infos!!.indices) {
try {
val info = infos!!
if (info is CellInfoLte) //if LTE connection
{
//mManager!!.getNetworkOperator()
lte = info.cellSignalStrength
identityLte = info.cellIdentity
ci = identityLte!!.ci
MCC = identityLte!!.mccString
MNC = identityLte!!.mncString
if(MNC == null || MCC == null) PLMN = "XXXX"
else if (MNC!!.length == 3) {
PLMN = "${MCC!![1]}${MCC!![0]}${MNC!![2]}${MCC!![2]}${MNC!![1]}${MNC!![0]}"
} else {
PLMN = "${MCC!![1]}${MCC!![0]}F${MCC!![2]}${MNC!![1]}${MNC!![0]}"
}
cellidHex = String.format("%x", ci)
eNBHex = cellidHex.substring(0, cellidHex.length - 2)
eNB = Integer.parseInt(eNBHex, 16)
//ECI = 256 * eNBId + Cellid
dataNeighbour["Registered"] = "${info!!.isRegistered()}"
if (preferences.NeighbourLteRsrp) dataNeighbour["RSRP"] = "${lte!!.rsrp}"
if (preferences.NeighbourLteRssi) dataNeighbour["RSSI"] = "${lte!!.rssi}" //Unavailable
if (preferences.NeighbourLteCqi) dataNeighbour["CQI"] = "${lte!!.cqi}" //Unavailable
if (preferences.NeighbourLteDbm) dataNeighbour["Dbm"] = "${lte!!.dbm}"
if (preferences.NeighbourLteLevel) dataNeighbour["LevelSignalStrength"] = "${lte!!.level}"
if (preferences.NeighbourLteRsrq) dataNeighbour["RSRQ"] = "${lte!!.rsrq}"
if (preferences.NeighbourLteRssnr) dataNeighbour["RSSNR"] = "${lte!!.rssnr}"
if (preferences.NeighbourLtePci) dataNeighbour["PCI"] = "${identityLte!!.pci}"
if (preferences.NeighbourLteCi) dataNeighbour["CI"] = "${ci}"
if (preferences.NeighbourLteMnc) dataNeighbour["MNC"] = "${MNC}"
if (preferences.NeighbourLteMcc) dataNeighbour["MCC"] = "${MCC}"
if (preferences.NeighbourLtePlmn) dataNeighbour["PLMN"] = "${PLMN}"
if (preferences.NeighbourLteEnb) dataNeighbour["eNB"] = "${eNB}"
if (preferences.NeighbourLteMobileNetworkOperator) dataNeighbour["MobileNetworkOperatorID"] = "${identityLte!!.mobileNetworkOperator}"
if (preferences.NeighbourLteMobileNetworkOperator) dataNeighbour["MobileNetworkOperatorName"] = "${identityLte!!.operatorAlphaLong}"
if (preferences.NeighbourLteTac) dataNeighbour["TAC"] = "${identityLte!!.tac}"
if (preferences.NeighbourLteBandwith) dataNeighbour["Bandwidth"] = "${identityLte!!.bandwidth}"
if (preferences.NeighbourLteEarfcn){
dataNeighbour["EarFCN"] = "${identityLte!!.earfcn}"
dataNeighbour["Band"] = "${getBand(identityLte!!.earfcn)}"
}
}else{
if (info is CellInfoGsm){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityGsm.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoCdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityCdma.networkId: ${identityGsm.networkId}, identityCdma.systemId: ${identityGsm.systemId}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoWcdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityWcdma.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoTdscdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityTdscdma.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}
}
} catch (ex: Exception) {
Log.i("TESTING: ", ex.message)
}
jsonObject.putOpt("Site$i", JSONObject(dataNeighbour as Map<*, *>))
}
mLteNeighbourData = jsonObject
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
stopSelf() //a hard stop for the service (si no queremos que siga en funcionamiento al cerrar)
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
super.onDestroy()
}
inner class MyBinder : Binder() {
fun getService(): ServiceLte? {
return [email protected]
}
}
private fun getBand(arfcn:Int):Int{
when {
arfcn<600 -> return 1
arfcn<1200 -> return 2
arfcn<1950 -> return 3
arfcn<2400 -> return 4
arfcn<2650 -> return 5
arfcn<2750 -> return 6
arfcn<3450 -> return 7
arfcn<3800 -> return 8
arfcn<4150 -> return 9
arfcn<4750 -> return 10
arfcn<5010 -> return 11
arfcn<5180 -> return 12
arfcn<5280 -> return 13
arfcn<5380 -> return 14
arfcn<5730 -> return -1
arfcn<5850 -> return 17
arfcn<6000 -> return 18
arfcn<6150 -> return 19
arfcn<6450 -> return 20
arfcn<6600 -> return 21
arfcn<7500 -> return 22
arfcn<7700 -> return 23
arfcn<8040 -> return 24
arfcn<8690 -> return 25
arfcn<9040 -> return 26
arfcn<9210 -> return 27
arfcn<9660 -> return 28
arfcn<9770 -> return 29
arfcn<9870 -> return 30
arfcn<9920 -> return 31
else -> return 9999
}
}
}
Click to expand...
Click to collapse
Here I also post the 5G NR service to obtain the information:
package com.mobilenet.monitoring.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Binder
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.telephony.*
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import com.mobilenet.monitoring.R
import com.mobilenet.monitoring.app.preferences
import org.json.JSONObject
class ServiceNr : Service() {
val TAG = "TESTING"
private var mBinder: IBinder = MyBinder()
private var mHandler = Handler()
/* Lte Parameters */
var mSignalStrength: SignalStrength? = null
var mListSignalStrength: List<CellSignalStrength>? = null
var mSignalStrengthNr: CellSignalStrengthNr? = null
var mManager: TelephonyManager? = null
/* LteConnection */
private var mNrData: JSONObject = JSONObject()
private var mNrNeighbourData: JSONObject = JSONObject()
var infos: MutableList<CellInfo>? = null
private lateinit var mContext:Context
private var jsonObject:JSONObject = JSONObject()
private var dataNeighbour = HashMap<String, String>()
private var nr:CellSignalStrengthNr? = null
private var identityNr:CellIdentityNr? = null
private var ci:Int = -1
private var MCC:String? = ""
private var MNC:String? = ""
private var PLMN:String? = ""
private var cellidHex: String = ""
private var eNBHex:String = ""
private var eNB: Int = -1
override fun onBind(intent: Intent): IBinder? {
return mBinder
}
@RequiresApi(Build.VERSION_CODES.Q)
@SuppressLint("MissingPermission")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate")
mContext = this
/* NR */
mManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
// Register the listener with the telephony manager
// mManager!!.listen( mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS or PhoneStateListener.LISTEN_CELL_LOCATION)
/*
SSB es el beam
*/
update()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if(intent?.getStringExtra("action") == "Destroy"){
onDestroy()
}
val CHANNELID = "Foreground Service ID"
val channel = NotificationChannel(
CHANNELID,
CHANNELID,
NotificationManager.IMPORTANCE_LOW
)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
val notification: Notification.Builder = Notification.Builder(this, CHANNELID)
.setContentText("Monitoring is running")
.setContentTitle("Monitoring enabled")
.setSmallIcon(R.drawable.ic_launcher_background)
startForeground(1001, notification.build())
return super.onStartCommand(intent, flags, startId)
}
fun getNrData(): JSONObject {
return mNrData
}
fun getNeighbourNrData(): JSONObject {
return mNrNeighbourData
}
fun destroy(){
stopSelf();
}
// Listener for signal strength.
private val mListener: PhoneStateListener = object : PhoneStateListener() {
override fun onSignalStrengthsChanged(sStrength: SignalStrength) {
mSignalStrength = sStrength
if (ActivityCompat.checkSelfPermission(
mContext,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED) {
infos = mManager!!.allCellInfo
}
}
override fun onCellInfoChanged(cellInfo: MutableList<CellInfo>) {
infos = cellInfo
}
}
private fun update() {
val runnable = object : Runnable {
@SuppressLint("MissingPermission", "NewApi")
override fun run() {
mManager!!.requestCellInfoUpdate( mContext.mainExecutor,
object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(cellInfo: MutableList<CellInfo>) {
mNrData = JSONObject()
mNrNeighbourData = JSONObject()
infos = null
jsonObject = JSONObject()
getData(cellInfo)
}
})
mHandler.postDelayed(this, 500)//preferences.periodicity.toLong())
}
}
mHandler.postDelayed(runnable, 500)//preferences.periodicity.toLong())
}
@SuppressLint("MissingPermission")
@RequiresApi(Build.VERSION_CODES.Q)
private fun getData(cellInfo: MutableList<CellInfo>){
try {
// Log.d(TAG, "$cellInfo") //Pondría esto para ver qué obtengo a ver si hay aquí algo mal
mSignalStrengthNr = (cellInfo[0] as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
//Nr connected
if (preferences.NeighbourNrEnable) {
if (preferences.NeighbourNrRsrp) mNrData.put(
"NrRsrp",
"${mSignalStrengthNr!!.ssRsrp}"
)
if (preferences.NeighbourNrRsrq) mNrData.put(
"NrRsrq",
"${mSignalStrengthNr!!.ssRsrq}"
)
if (preferences.NeighbourNrSinr) mNrData.put(
"NrSinr",
"${mSignalStrengthNr!!.ssSinr}"
)
if (preferences.NeighbourNrAsulevel) mNrData.put(
"NrAsulevel",
"${mSignalStrengthNr!!.asuLevel}"
)
if (preferences.NeighbourNrDbm) mNrData.put(
"NrDbm",
"${mSignalStrengthNr!!.dbm}"
)
if (preferences.NeighbourNrLevel) mNrData.put(
"NrLevel",
"${mSignalStrengthNr!!.level}"
)
}
}catch (ex: Exception) {
Log.i(TAG, ex.message)
}
infos = mManager!!.allCellInfo
// Log.d(TAG, "$infos") //Pondría esto para ver qué obtengo a ver si hay aquí algo mal
jsonObject = JSONObject()
dataNeighbour = HashMap<String, String>()
if (preferences.NeighbourNrEnable){
jsonObject.put("NumberOfSites", "${infos!!.size}")
}
for (i in infos!!.indices) {
try {
val cell = infos!!
nr = (cell as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
identityNr = (cell as CellInfoNr).cellIdentity as CellIdentityNr
// nr = (cellInfo[0] as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
// identityNr = (cellInfo[0] as CellInfoNr).cellIdentity as CellIdentityNr
// Log.d(TAG,"${infos!!.indices}")
// Log.d(TAG,nr.toString())
// Log.d(TAG,identityNr.toString())
ci = identityNr!!.pci
MCC = identityNr!!.mccString
MNC = identityNr!!.mncString
if(MNC == null || MCC == null)
{
PLMN = "XXXX"
}
else if (MNC!!.length == 3) {
PLMN = "${MCC!![1]}${MCC!![0]}${MNC!![2]}${MCC!![2]}${MNC!![1]}${MNC!![0]}"
} else {
PLMN = "${MCC!![1]}${MCC!![0]}F${MCC!![2]}${MNC!![1]}${MNC!![0]}"
}
if (preferences.NeighbourNrRsrp){
var rsrp = nr!!.ssRsrp
dataNeighbour["RSRP"] = "${rsrp}"
}
if (preferences.NeighbourNrRsrq){
var rsrq = nr!!.ssRsrq
dataNeighbour["RSRP"] = "${rsrq}"
}
if (preferences.NeighbourNrSinr){
var sinr = nr!!.ssSinr
dataNeighbour["Sinr"] = "${sinr}"
}
if (preferences.NeighbourNrAsulevel){
var asulevel = nr!!.asuLevel
dataNeighbour["Asulevel"] = "${asulevel}"
}
if (preferences.NeighbourNrDbm){
var dbm = nr!!.dbm
dataNeighbour["Dbm"] = "${dbm}"
}
if (preferences.NeighbourNrLevel){
var level = nr!!.level
dataNeighbour["Level"] = "${level}"
}
dataNeighbour["PCI"] = "${identityNr!!.pci}"
dataNeighbour["CI"] = "${ci}"
dataNeighbour["MNC"] = "${MNC}"
dataNeighbour["MCC"] = "${MCC}"
dataNeighbour["PLMN"] = "${PLMN}"
dataNeighbour["MobileNetworkOperatorName"] = "${identityNr!!.operatorAlphaLong}"
dataNeighbour["TAC"] = "${identityNr!!.tac}"
dataNeighbour["EarFCN"] = "${identityNr!!.nrarfcn}"
} catch (ex: Exception) {
Log.i("TESTING: ", ex.message)
}
jsonObject.putOpt("Site$i", JSONObject(dataNeighbour as Map<*, *>))
}
mNrNeighbourData = jsonObject
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
stopSelf() //a hard stop for the service (si no queremos que siga en funcionamiento al cerrar)
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
super.onDestroy()
}
inner class MyBinder : Binder() {
fun getService(): ServiceNr? {
return [email protected]ServiceNr
}
}
private fun getBand(arfcn: Int):Int{
when {
arfcn<600 -> return 1
arfcn<1200 -> return 2
arfcn<1950 -> return 3
arfcn<2400 -> return 4
arfcn<2650 -> return 5
arfcn<2750 -> return 6
arfcn<3450 -> return 7
arfcn<3800 -> return 8
arfcn<4150 -> return 9
arfcn<4750 -> return 10
arfcn<5010 -> return 11
arfcn<5180 -> return 12
arfcn<5280 -> return 13
arfcn<5380 -> return 14
arfcn<5730 -> return -1
arfcn<5850 -> return 17
arfcn<6000 -> return 18
arfcn<6150 -> return 19
arfcn<6450 -> return 20
arfcn<6600 -> return 21
arfcn<7500 -> return 22
arfcn<7700 -> return 23
arfcn<8040 -> return 24
arfcn<8690 -> return 25
arfcn<9040 -> return 26
arfcn<9210 -> return 27
arfcn<9660 -> return 28
arfcn<9770 -> return 29
arfcn<9870 -> return 30
arfcn<9920 -> return 31
else -> return 9999
} //Ya paso de seguir haciendo la tabla https://5g-tools.com/4g-lte-earfcn-calculator/
}
}
Click to expand...
Click to collapse

Categories

Resources