Work on supporting adhoc network mode.
This commit is contained in:
parent
2feabd7a5b
commit
bbe0451a8b
4 changed files with 232 additions and 18 deletions
|
@ -421,7 +421,14 @@ function set_netplay() {
|
|||
echo -n " --host"
|
||||
;;
|
||||
client)
|
||||
local NETPLAY_HOST_IP=$(get_setting global.netplay.host)
|
||||
local ADHOC_NETWORK=$(get_setting network.adhoc.enabled)
|
||||
|
||||
if [ "${ADHOC_NETWORK}" = "1" ]
|
||||
then
|
||||
local NETPLAY_HOST_IP="192.168.1.1"
|
||||
else
|
||||
local NETPLAY_HOST_IP=$(get_setting global.netplay.host)
|
||||
fi
|
||||
add_setting "none" "netplay_mode" "true"
|
||||
add_setting "none" "netplay_client_swap_input" "true"
|
||||
add_setting "global.netplay.port" "netplay_ip_port"
|
||||
|
|
|
@ -29,7 +29,13 @@ else
|
|||
PSK="$(get_setting wifi.key)" 2>/dev/null
|
||||
fi
|
||||
|
||||
WIFICFG="/storage/.cache/connman/wifi.config"
|
||||
###
|
||||
### Basic WIFI properties used across the tool.
|
||||
###
|
||||
|
||||
WIFI_CFG="/storage/.cache/connman/wifi.config"
|
||||
WIFI_TYPE=$(get_setting network.adhoc.enabled)
|
||||
ADHOC_FREQ="5280"
|
||||
|
||||
# lists all wifi services in service=ssid format
|
||||
list_wifi() {
|
||||
|
@ -60,8 +66,8 @@ get_wifi_state() {
|
|||
}
|
||||
|
||||
check_wifi() {
|
||||
SSID_CHK=$(grep "${SSID}" ${WIFICFG} 2>/dev/null)
|
||||
KEY_CHK=$(grep "${PSK}" ${WIFICFG} 2>/dev/null)
|
||||
SSID_CHK=$(grep "${SSID}" ${WIFI_CFG} 2>/dev/null)
|
||||
KEY_CHK=$(grep "${PSK}" ${WIFI_CFG} 2>/dev/null)
|
||||
STATE=$(get_wifi_state)
|
||||
if [ -n "${SSID_CHK}" ] && \
|
||||
[ -n "${KEY_CHK}" ] && \
|
||||
|
@ -72,23 +78,74 @@ check_wifi() {
|
|||
}
|
||||
|
||||
connect_wifi() {
|
||||
NETCHECK=$(systemctl status connman >/dev/null 2>&1)
|
||||
if [ ! "$?" = "0" ]
|
||||
|
||||
### Make sure the service is available
|
||||
NETCHECK=$(systemctl is-actove connman >/dev/null 2>&1)
|
||||
if [ "${NETCHECK}" = "inactive" ]
|
||||
then
|
||||
systemctl start connman
|
||||
systemctl restart connman >/dev/null 2>&1
|
||||
systemctl restart wpa_supplicant 2>&1
|
||||
fi
|
||||
|
||||
### If we aren't already online. Go online.
|
||||
STATE=$(get_wifi_state)
|
||||
if [ ! "${STATE}" = "online" ]
|
||||
then
|
||||
connmanctl enable wifi 2>/dev/null
|
||||
fi
|
||||
rfkill unblock wifi 2>/dev/null
|
||||
connmanctl connect $(get_wifi_service "${SSID}")
|
||||
|
||||
set_powersave 2>/dev/null
|
||||
}
|
||||
|
||||
connect_adhoc() {
|
||||
local CLIENT=$(get_setting wifi.adhoc.id)
|
||||
rfkill unblock wifi
|
||||
|
||||
### Set the WIFI type to ad-hoc
|
||||
iw dev wlan0 del
|
||||
iw phy phy0 interface add wlan0 type ibss
|
||||
|
||||
### Start the interfaece
|
||||
ip link set wlan0 up >/dev/null 2>&1
|
||||
|
||||
### Create / join the adhoc network
|
||||
iw wlan0 ibss join ${SSID}-adhoc ${ADHOC_FREQ} >/dev/null 2>&1
|
||||
|
||||
iw wlan0 connect ${SSID}-adhoc
|
||||
|
||||
### Enable security
|
||||
cat <<EOF >/storage/.cache/.adhoc.conf
|
||||
ap_scan=2
|
||||
|
||||
network={
|
||||
ssid="${SSID}-adhoc"
|
||||
mode=1
|
||||
frequency=${ADHOC_FREQ}
|
||||
proto=RSN
|
||||
key_mgmt=WPA-PSK
|
||||
pairwise=CCMP
|
||||
group=CCMP
|
||||
psk="${PSK}"
|
||||
}
|
||||
EOF
|
||||
|
||||
wpa_supplicant -B -i wlan0 -c /storage/.cache/.adhoc.conf -D nl80211,wext
|
||||
|
||||
### Set our IP
|
||||
ip addr add 192.168.0.${CLIENT}/24 dev wlan0 >/dev/null 2>&1
|
||||
}
|
||||
|
||||
disconnect_adhoc() {
|
||||
ip addr flush dev wlan0 >/dev/null 2>&1
|
||||
ip link set wlan0 down >/dev/null 2>&1
|
||||
killall wpa_supplicant
|
||||
### Set the WIFI type to ad-hoc
|
||||
iw dev wlan0 del
|
||||
iw phy phy0 interface add wlan0 type managed
|
||||
}
|
||||
|
||||
set_profile() {
|
||||
cat > "${WIFICFG}" <<EOF
|
||||
cat > "${WIFI_CFG}" <<EOF
|
||||
[service_${OS_NAME}_default]
|
||||
Type = wifi
|
||||
Name = ${SSID}
|
||||
|
@ -98,15 +155,32 @@ EOF
|
|||
|
||||
case "${1}" in
|
||||
enable)
|
||||
check_wifi
|
||||
case ${WIFI_TYPE} in
|
||||
1)
|
||||
systemctl stop wpa_supplicant >/dev/null 2>&1
|
||||
systemctl stop connman >/dev/null 2>&1
|
||||
connect_adhoc >/dev/null 2>&1
|
||||
;;
|
||||
*)
|
||||
check_wifi >/dev/null 2>&1
|
||||
disconnect_adhoc >/dev/null 2>&1
|
||||
set_profile >/dev/null 2>&1
|
||||
connect_wifi >/dev/null 2>&1
|
||||
;;
|
||||
esac
|
||||
set_setting wifi.enabled 1
|
||||
set_profile
|
||||
connect_wifi
|
||||
;;
|
||||
disable)
|
||||
case ${WIFI_TYPE} in
|
||||
1)
|
||||
disconnect_adhoc >/dev/null 2>&1
|
||||
;;
|
||||
*)
|
||||
connmanctl disable wifi >/dev/null 2>&1
|
||||
rm -f "${WIFI_CFG}" 2>/dev/null
|
||||
;;
|
||||
esac
|
||||
rfkill block wifi
|
||||
connmanctl disable wifi
|
||||
rm -f "${WIFICFG}" 2>/dev/null
|
||||
set_setting wifi.enabled 0
|
||||
;;
|
||||
reconnect)
|
||||
|
@ -114,7 +188,6 @@ case "${1}" in
|
|||
/usr/bin/wifictl enable
|
||||
;;
|
||||
list)
|
||||
#connmanctl services | cut -b 5- | awk '/wifi/ {sub(/\s+wifi_.*$/,"",$0);print}' | sort | uniq
|
||||
list_wifi | awk '{sub(/\S+=/,"",$0);print}'
|
||||
;;
|
||||
scan)
|
||||
|
@ -134,4 +207,3 @@ case "${1}" in
|
|||
set_profile
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -88,5 +88,5 @@ post_install() {
|
|||
add_user system x 430 430 "service" "/var/run/connman" "/bin/sh"
|
||||
add_group system 430
|
||||
|
||||
enable_service connman.service
|
||||
#enable_service connman.service
|
||||
}
|
||||
|
|
135
packages/ui/emulationstation/patches/001-adhoc.patch
Normal file
135
packages/ui/emulationstation/patches/001-adhoc.patch
Normal file
|
@ -0,0 +1,135 @@
|
|||
diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp
|
||||
index b608b6c..f6c3414 100644
|
||||
--- a/es-app/src/guis/GuiMenu.cpp
|
||||
+++ b/es-app/src/guis/GuiMenu.cpp
|
||||
@@ -4212,9 +4212,10 @@ void GuiMenu::openWifiSettings(Window* win, std::string title, std::string data,
|
||||
win->pushGui(new GuiWifi(win, title, data, onsave));
|
||||
}
|
||||
|
||||
-void GuiMenu::openNetworkSettings_batocera(bool selectWifiEnable)
|
||||
+void GuiMenu::openNetworkSettings_batocera(bool selectWifiEnable, bool selectAdhocEnable)
|
||||
{
|
||||
bool baseNetworkEnabled = SystemConf::getInstance()->getBool("network.enabled");
|
||||
+ bool adhocEnabled = SystemConf::getInstance()->getBool("network.adhoc.enabled");
|
||||
|
||||
auto theme = ThemeData::getMenuTheme();
|
||||
std::shared_ptr<Font> font = theme->Text.font;
|
||||
@@ -4244,54 +4245,57 @@ void GuiMenu::openNetworkSettings_batocera(bool selectWifiEnable)
|
||||
s->addInputTextRow(_("HOSTNAME"), "system.hostname", false);
|
||||
#endif
|
||||
|
||||
-// std::string a;
|
||||
-// auto bluetoothd_enabled = std::make_shared<SwitchComponent>(mWindow);
|
||||
-// bool btbaseEnabled = SystemConf::getInstance()->get("bluetooth.enabled") == "1";
|
||||
-// bluetoothd_enabled->setState(btbaseEnabled);
|
||||
-// s->addWithLabel(_("ENABLE BLUETOOTH"), bluetoothd_enabled);
|
||||
-// s->addSaveFunc([bluetoothd_enabled] {
|
||||
-// if (bluetoothd_enabled->changed()) {
|
||||
-// if (bluetoothd_enabled->getState() == false) {
|
||||
-// runSystemCommand("systemctl stop bluetooth", "", nullptr);
|
||||
-// runSystemCommand("rm /storage/.cache/services/bluez.conf", "", nullptr);
|
||||
-// } else {
|
||||
-// runSystemCommand("mkdir -p /storage/.cache/services/", "", nullptr);
|
||||
-// runSystemCommand("touch /storage/.cache/services/bluez.conf", "", nullptr);
|
||||
-// runSystemCommand("systemctl start bluetooth", "", nullptr);
|
||||
-// }
|
||||
-// bool bluetoothenabled = bluetoothd_enabled->getState();
|
||||
-// SystemConf::getInstance()->set("bluetooth.enabled", bluetoothenabled ? "1" : "0");
|
||||
-// SystemConf::getInstance()->saveSystemConf();
|
||||
-// }
|
||||
-// });
|
||||
-
|
||||
// Wifi enable
|
||||
auto enable_net = std::make_shared<SwitchComponent>(mWindow);
|
||||
+ auto enable_adhoc = std::make_shared<SwitchComponent>(mWindow);
|
||||
+
|
||||
enable_net->setState(baseNetworkEnabled);
|
||||
+ enable_adhoc->setState(adhocEnabled);
|
||||
+
|
||||
s->addWithLabel(_("ENABLE NETWORK"), enable_net, selectWifiEnable);
|
||||
|
||||
// window, title, settingstring,
|
||||
const std::string baseSSID = SystemConf::getInstance()->get("wifi.ssid");
|
||||
const std::string baseKEY = SystemConf::getInstance()->get("wifi.key");
|
||||
|
||||
- if (baseNetworkEnabled)
|
||||
+ auto optionsAdhocID = std::make_shared<OptionListComponent<std::string> >(mWindow, _("ADHOC ID"), false);
|
||||
+
|
||||
+ // Adhoc mode options
|
||||
+ enable_adhoc->setState(adhocEnabled);
|
||||
+ s->addWithLabel(_("ADHOC NETWORK MODE"), enable_adhoc, selectAdhocEnable);
|
||||
+
|
||||
+ std::string selectedAdhocID = SystemConf::getInstance()->get("wifi.adhoc.id");
|
||||
+ if (selectedAdhocID.empty())
|
||||
{
|
||||
- s->addInputTextRow(_("WIFI SSID"), "wifi.ssid", false, false, &openWifiSettings);
|
||||
- s->addInputTextRow(_("WIFI KEY"), "wifi.key", true);
|
||||
+ selectedAdhocID = "1";
|
||||
}
|
||||
+ optionsAdhocID->add(_("1 (HOST)"),"1", selectedAdhocID == "1");
|
||||
+ optionsAdhocID->add(_("2 (CLIENT 1)"),"2", selectedAdhocID == "2");
|
||||
+ optionsAdhocID->add(_("3 (CLIENT 2)"),"3", selectedAdhocID == "3");
|
||||
+ optionsAdhocID->add(_("4 (CLIENT 3)"),"4", selectedAdhocID == "4");
|
||||
+ s->addWithLabel(_("ADHOC ID"), optionsAdhocID);
|
||||
+
|
||||
+ s->addInputTextRow(_("WIFI SSID"), "wifi.ssid", false, false, &openWifiSettings);
|
||||
+ s->addInputTextRow(_("WIFI KEY"), "wifi.key", true);
|
||||
|
||||
- s->addSaveFunc([baseNetworkEnabled, baseSSID, baseKEY, enable_net, window]
|
||||
+ s->addSaveFunc([baseNetworkEnabled, selectAdhocEnable, baseSSID, baseKEY, enable_net, enable_adhoc, optionsAdhocID, selectedAdhocID, window]
|
||||
{
|
||||
bool networkenabled = enable_net->getState();
|
||||
+ bool adhocenabled = enable_adhoc->getState();
|
||||
+
|
||||
+ SystemConf::getInstance()->setBool("network.adhoc.enabled", adhocenabled);
|
||||
+ SystemConf::getInstance()->set("wifi.adhoc.id", optionsAdhocID->getSelected());
|
||||
|
||||
SystemConf::getInstance()->setBool("network.enabled", networkenabled);
|
||||
|
||||
+ SystemConf::getInstance()->saveSystemConf();
|
||||
+
|
||||
if (networkenabled)
|
||||
{
|
||||
std::string newSSID = SystemConf::getInstance()->get("wifi.ssid");
|
||||
std::string newKey = SystemConf::getInstance()->get("wifi.key");
|
||||
|
||||
- if (baseSSID != newSSID || baseKEY != newKey || !baseNetworkEnabled)
|
||||
+ if (baseSSID != newSSID || baseKEY != newKey || !baseNetworkEnabled || !selectAdhocEnable)
|
||||
{
|
||||
if (ApiSystem::getInstance()->enableWifi(newSSID, newKey))
|
||||
window->pushGui(new GuiMsgBox(window, _("WIFI ENABLED")));
|
||||
@@ -4301,14 +4305,19 @@ void GuiMenu::openNetworkSettings_batocera(bool selectWifiEnable)
|
||||
}
|
||||
else if (baseNetworkEnabled)
|
||||
ApiSystem::getInstance()->disableWifi();
|
||||
+
|
||||
});
|
||||
|
||||
- enable_net->setOnChangedCallback([this, s, baseNetworkEnabled, enable_net]()
|
||||
+ enable_net->setOnChangedCallback([this, s, baseNetworkEnabled, enable_net, adhocEnabled, enable_adhoc]()
|
||||
{
|
||||
+
|
||||
bool networkenabled = enable_net->getState();
|
||||
- if (baseNetworkEnabled != networkenabled)
|
||||
+ bool adhocenabled = enable_adhoc->getState();
|
||||
+
|
||||
+ if (baseNetworkEnabled != networkenabled || adhocEnabled != adhocenabled)
|
||||
{
|
||||
SystemConf::getInstance()->setBool("network.enabled", networkenabled);
|
||||
+ SystemConf::getInstance()->setBool("network.adhoc.enabled", adhocenabled);
|
||||
|
||||
if (networkenabled)
|
||||
ApiSystem::getInstance()->enableWifi(SystemConf::getInstance()->get("wifi.ssid"), SystemConf::getInstance()->get("wifi.key"));
|
||||
diff --git a/es-app/src/guis/GuiMenu.h b/es-app/src/guis/GuiMenu.h
|
||||
index bead7f5..ac44267 100644
|
||||
--- a/es-app/src/guis/GuiMenu.h
|
||||
+++ b/es-app/src/guis/GuiMenu.h
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
void openSystemSettings_batocera();
|
||||
void openGamesSettings_batocera();
|
||||
void openControllersSettings_batocera(int autoSel = 0);
|
||||
- void openNetworkSettings_batocera(bool selectWifiEnable = false);
|
||||
+ void openNetworkSettings_batocera(bool selectWifiEnable = false, bool selectAdhocEnable = false);
|
||||
void openQuitMenu_batocera();
|
||||
void openSystemInformations_batocera();
|
||||
void openDeveloperSettings();
|
Loading…
Reference in a new issue