android 10 how to disable Randomized Mac Address in source code - android

Currently, I am working on connecting specific WiFi in the source code.
But the problem is, since Android 10, the default setting is to set a random macArress.
Yeah i forcibly set the mac adrress to wifi info or I want to turn off random mac adrress option
this is my code
if(BasicInfo.wifiEncryption == BasicInfo.WPA_PSK){
BasicInfo.debug(TAG,"setWiFiConfigForJellyBean :BasicInfo.WPA_PSK");
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.preSharedKey = "\"".concat(BasicInfo.WIFI_PASSWORD).concat("\"");
BasicInfo.debug(TAG,"BasicInfo.WPA_PSK Password :" + BasicInfo.WIFI_PASSWORD);
}

Related

streaming UDP packets with esp32 access point cause massive packet loss

I'm currently running my esp32 wroom as Access Point to stream UDP packets (~100 packets per second, 1Ko per packet) to different smartphones.
At close range, I lost about 30% of the packets at steady rate.
It not unusual to lose packets with UDP protocol however this issue happens only with some specific and quite recent smartphones.
After some Wireshark investigations of the Wifi messages, I observe that this packet loss is happening only for smartphones using IEEE 802.11 Power Save mecanism.
There are plenty of options regarding Power saving mode in ESP 32 configuration and I suspect that I may have misconfigured the ESP32.
Do you have an idea of what could cause the problem ?
Thanks
I'm sharing with you the ESP32 configuration:
#
# Wi-Fi
#
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=64
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
# CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER is not set
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=32
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=32
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=32
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
# CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE is not set
CONFIG_ESP32_WIFI_IRAM_OPT=y
CONFIG_ESP32_WIFI_RX_IRAM_OPT=y
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_SLP_IRAM_OPT is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
# end of Wi-Fi
see the Access point initialization code:
esp_err_t COM_wifi_access_point_start(void)
{
esp_err_t esp_err;
do {
// Initialization of the physical WiFi port
tcpip_adapter_init();
// Shutdown of the DHCP server before reprogramming the IP address of the probe
BREAK_ON_ERR( esp_err = tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP) );
// Initialization of the structure containing the IP address of the probe
tcpip_adapter_ip_info_t ip_info;
IP4_ADDR(&ip_info.ip,EPF_IPV4_IP_ADDR_1,EPF_IPV4_IP_ADDR_2,EPF_IPV4_IP_ADDR_3,EPF_IPV4_IP_ADDR_4);
IP4_ADDR(&ip_info.gw,EPF_IPV4_GW_ADDR_1,EPF_IPV4_GW_ADDR_2,EPF_IPV4_GW_ADDR_3,EPF_IPV4_GW_ADDR_4);
IP4_ADDR(&ip_info.netmask,EPF_IPV4_NM_ADDR_1,EPF_IPV4_NM_ADDR_2,EPF_IPV4_NM_ADDR_3,EPF_IPV4_NM_ADDR_4);
// The new IP address is applied
BREAK_ON_ERR( esp_err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info) );
// Restarting the DHCP server
BREAK_ON_ERR( esp_err = tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP) );
// Connecting the IT WiFi handler
BREAK_ON_ERR( esp_err = esp_event_loop_init(wifi_event_handler, NULL) );
// Initialization of the WiFi driver to the default configuration
wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
BREAK_ON_ERR( esp_err = esp_wifi_init(&wifi_init_config) );
// The driver is told to store all WiFi configuration in RAM
// => We don't always write the configuration in flash each time
BREAK_ON_ERR( esp_err = esp_wifi_set_storage(WIFI_STORAGE_RAM) );
// Switching from the default connection mode to Access Point mode
BREAK_ON_ERR( esp_err = esp_wifi_set_mode(WIFI_MODE_AP) );
// The desired configuration is applied to the WiFi driver
wifi_config_t ap_config =
{
.ap =
{
.ssid = "",
.channel = EPF_WIFI_CHANNEL_NUMBER,
.password = EPF_WIFI_PASSWORD,
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
.ssid_hidden = COM_WIFI_BROADCAST, // SSID in broadcast mode => Non-hidden network
.max_connection = EPF_WIFI_NB_CONNECTION, // Only one connection allowed simultaneously
.beacon_interval= COM_WIFI_BEACON_INT
}
};
sprintf((char*)ap_config.ap.ssid, EPF_WIFI_SSID_TMPL, PAR_get_live_raw_fast(EPF_MAI_PROBE_SERIAL_NB) );
BREAK_ON_ERR( esp_err = esp_wifi_set_config(WIFI_IF_AP, &ap_config) );
// Starting WiFi
// After calling this function, the access point is visible from remote WiFi devices
BREAK_ON_ERR( esp_err = esp_wifi_start() );
// Renaming the hostname
BREAK_ON_ERR( esp_err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, COM_LOCALHOSTNAME) );
esp_err = ESP_OK;
} while(0);
return esp_err;
}
The ESP32-s WiFi power saving is enabled by default. You can disable it with a call to esp_wifi_set_ps(WIFI_PS_NONE); - see if it works for you. I've had to turn it off after I saw significant ICMP packet loss under load.

Android 8 (Oreo) WifiManager reconnect method times out

I am having an issue. The app I am busy with has a strange issue at the moment. I use the following library: WiseFly which is a simple wifi manager wrapper
My app manages WiFi networks. It will add to saved networks and connects to it depending on users interaction with my app. It works perfectly on all versions of android, except for Android Oreo on my Pixel.
It times out on the following line internally on the wrapper:
getWifiManager().disconnect();
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);
getWifiManager().reconnect();
The last line is the issue. And if I go into the network settings on android, I see the saved network, but will also not connect from within android. Any ideas what I could look for to fix this issue?
This is the code used to add the network:
/**
* To generate a configuration for a WPA2 network
*
* #param ssid The ssid for the WPA2 network's configuration
* #param password The password for the WPA2 network's configuration
*
* #return WifiConfiguration - The WPA2 network configuration
*/
public WifiConfiguration generateWPA2NetworkConfiguration(String ssid, String password) {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = mSSIDUtil.convertSSIDForConfig(ssid);
wifiConfiguration.preSharedKey = "\"" + password + "\"";
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
return wifiConfiguration;
}
Any help would be greatly appreciated.
Thanks
Try this
// Allow a previously configured network to be associated with.
getWifiManager().enableNetwork(wifiConfiguration.networkId, true);
// Reconnect to the currently active access point, if we are currently disconnected.
getWifiManager().reconnect();
// wait until reconnect process is completed
Thread.sleep(3000);

Can't connect HM10 to Android device

I am currently developing a device that uses a Pro Micro micro-controller, an HM10 ble module (I checked and this isn't a BLE-CC41A), and several Android devices. My issue is the connection between the Android and the HM10. A few days ago the connection between these two worked well and I could send and receive messages between these two. Now the Android can see the HM10 module but for some reason it cannot connect. I have tried several applications such as "nRF Connect", "BLE Scanner", and "MSMBle" all with no results.
All seems fine on the Pro Micro side. With the code I am using I can send AT commands to the HM10. In case you were wondering what code I used for the pro micro:
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(9, 8); //RX|TX
void setup(){
Serial.begin(9600);
bluetooth.begin(9600); // default baud rate
Serial.println("AT commands: ");
}
void loop(){
bluetoothCommunication();
serialCommunication();
}
void serialCommunication() {
if(Serial.available() >0){ //read from the Serial and print to the HM-10
bluetooth.write(Serial.read());
}
}
void bluetoothCommunication(){
String readStr; //expect a string like wer,qwe rty,123 456,hyre kjhg, or like hello world,who are you?,bye!,
while (bluetooth.available() > 0) { //read from the HM-10 and print in the Serial
delay(10); //small delay to allow input buffer to fill
char inChar = bluetooth.read(); //gets one byte from serial buffer
readStr += inChar ; //makes the string readString
}
if (readStr.length() >0) {
Serial.println(readStr); //prints string to serial port out
}
}
About the BLE HM10 module I pretty much use the default settings but changed the name and password. I also want to note that I tested with three HM10 modules and none can connect to an Android device.
Has anyone had the same issue? Did Android make an update that made HM10 modules unusable?

android mobile socket open

Why Socket can be open on the android emulator and connect to the python server code and open a socket !! In other Hand When i run same android code on the mobile it doesn't run . didnt open a socket ..Any suggestion what is the problem and how to solve such thing
enter code here
import sys
from threading import Thread
import socket
import MySQLdb
allClients=[]
class Client(Thread):
def __init__(self,clientSocket):
Thread.__init__(self)
self.sockfd = clientSocket #socket client
self.name = ""
self.nickName = ""
def newClientConnect(self):
allClients.append(self.sockfd)
while True:
while True:
try:
rm= self.sockfd.recv(2048)
print rm
i=0
while (i<2):
if (rm) == row[i][0]:
reply="\n Welcome to our game %s: %s"%(rm,row[i][1])
self.sockfd.send(reply)
break
else:
i=i+1
if i==2:
reply="\n Error opaa ba2a"
self.sockfd.send(reply)
i=0
break
break
except ValueError:
self.sockfd.send("\n UNVAlied Comment ")
def run(self):
self.newClientConnect()
while True:
buff = self.sockfd.recv(2048)
if buff.strip() == 'quit':
self.sockfd.close()
break # Exit when break
else:
self.sendAll(buff)
#Main
if __name__ == "__main__":
#Server Connection to socket:
IP = '50.0.10.107'
PORT = 5807
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
print ("Server Started")
try:
serversocket.bind(('',54633))
except ValueError,e:
print e
serversocket.listen(5)
db= MySQLdb.connect(host= "localhost",
user="root",
passwd="newpassword",
db="new_schema")
x=db.cursor()
x.execute("SELECT * FROM lolo")
row = x.fetchall()
print "Connected to the Database"
while True:
(clientSocket, address) = serversocket.accept()
print 'New connection from ', address
ct = Client(clientSocket)
ct.start()
__all__ = ['allClients','Client']
The python code and the server code it map and button when click on button connection start and it work great on the emulator
Could be a number of thing:
You don't have networking permissions enabled in your manifest file
Your wifi / 3G is disabled
If your server is on your personal computer and you're connected to the internet using a router then you need to redirect the port you're using for socket communication from the router to your machine.
If your code works on emulator but not on real phone, that could be a network issue. Emulator depends on LAN to access your server and phone access through 3G network. Is your server accessible through internet?

Unable to configure the wifi open network programmatically android?

I have written code for adding open network to wifi configured list.It adds the open network to configured lists and displays the same SSID's in Wifi Settings.but it adds the same network with same name extra but it doesn't shows any open network When i press on the second on alert shows with Security WEP the following text i observed with those same networks
1) Open network
2) remembered , not in range
But i want to add open network into my list, why this extra one is added and if i connect the same network it is trying to connect to the (2) one programmatically.Actually I changed secured network to open network for this trial.It displays with open network text and when i press on that one it obtains the address and connects succesfully manually.Why this extra one is adding how can i add the open network to my list.For reference plz see the link for image.
http://www.freeimagehosting.net/uploads/3dbccfc2bd.png
Code snippet :
String hotSpotSsid = hotSpot.SSID;
String hotSpotBssid = hotSpot.BSSID;
Log.i(TAG,"in RSSI Changed Acion SSID: "+hotSpotSsid+" BSSID: "+hotSpotBssid);
StringBuffer sBuf = new StringBuffer("\"");
sBuf.append(hotSpotSsid+"\"");
hotSpotSsid = sBuf.toString();
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = hotSpotSsid;
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfiguration.BSSID = hotSpotBssid;
wifiConfiguration.hiddenSSID = false;
// wifiConfiguration.priority = 1;
// add this to the configured networks
int inetId = wifiManager.addNetwork(wifiConfiguration);
Log.i(TAG,"INetId :"+inetId);
configs = wifiManager.getConfiguredNetworks();
Log.e(TAG,"After adding config :"+configs);
if(inetId < 0) {
Log.i(TAG,"Unable to add network configuration for SSID: "+hotSpotSsid);
return;
}else {
message="\t Successfully added to configured Networks";
Log.i(TAG,message);
}
regards,
Rajendar
Try removing SSID and seeing if it works. I was having a similar issue and that worked for me.
Appending and prepending quotes to the SSID, as you did, should work though. Not sure why it doesn't.
Give SSID as wifiConfiguration.SSID = "\"".concat(SSID_NAME).concat("\"");

Categories

Resources