networkimprov / arch-packages

1 stars 0 forks source link

wifi p2p in systemd unit #15

Open networkimprov opened 9 years ago

networkimprov commented 9 years ago

o.015. wifi p2p in systemd unit also consider prefixes on files we add to /usr/bin: anvl_* ? Package: anvl-net Status: in-progress

networkimprov commented 9 years ago

Hi. Given this start sequence:

ip link set p2p0 up
ip addr add 192.168.3.11/24 dev p2p0
wpa_supplicant -B -i p2p0 -D nl80211 -c /etc/wpa_supplicant/wpa_supplicant-p2p.conf \
  -f /var/log/wpa_supplicant-p2p.log
udhcpd /etc/udhcpd-p2p.conf

Is this the right stop sequence? I found the wpa_supplicant command on a linux forum, the one for udhcp is a guess...

kill -s SIGQUIT $(pidof udhcpd)
kill -s SIGQUIT $(cat /var/run/wpa_supplicant/p2p0.pid)
ip link set p2p0 down

Also was there a reason to select 192.168.3.11/24? If so I'll add a comment about it.

networkimprov commented 9 years ago

Here's what I've got for the .service, any fixes/additions?

[Unit]
Description=Enable WiFi P2P

[Service]
Type=forking
ExecStart=/usr/bin/wifi-p2p.sh start
ExecStop=/usr/bin/wifi-p2p.sh stop

[Install]
WantedBy=multi-user.target
thomasdziedzic commented 9 years ago

The .service looks good.

To kill udhcp, the service file performs the following:

ExecStop=/bin/kill -TERM $MAINPID

The wpa_supplicant service files don't seem to have a stop, though I found that the following could be a possibility: wpa_cli terminate. wpa_cli comes with wpa_supplicant.

With regards to why I used the specific ip 192.168.3.11, I think that was the ip that your example commands used so I used the same ip.

networkimprov commented 9 years ago

Do I need Wants= or Before= in this .service? I think Type=forking is wrong.

We will have two wpa_supplicant daemons running, so can't kill them both. Some .service files I've seen simply ip link set x down, so maybe the daemons quit then.

Ah we have a udhcp pkg, but it's not enabled. Should we rename udhcp.service => udhcp-example.service?

networkimprov commented 9 years ago

Having read more on systemd services, I think we want separate units, rather than one unit and a shell script. How's the following look?

udhcpd-p2p.service

[Unit]
Description=udhcpd for WiFi P2P on mwifiex driver
After=network.target

[Service]
Type=forking
ExecStartPre=bash -c "\
  if ! ip addr show p2p0 &> /dev/null; then \
    iw phy phy0 interface add p2p0 type __p2pcl; \
    sleep 1; \
    ip addr add 192.168.3.11/24 dev p2p0; \
  fi"
ExecStartPre=ip link set p2p0 up
ExecStart=udhcpd /etc/udhcpd-p2p0.conf
ExecStop=
ExecStopPost=ip link set p2p0 down

[Install]

wpa_supplicant-p2p.service

[Unit]
Description=WiFi P2P on mwifiex driver
Wants=udhcpd-p2p0.service
After=udhcpd-p2p0.service

[Service]
Type=forking
ExecStart=wpa_supplicant -B -P /var/run/wpa_supplicant_p2p0.pid -i p2p0 -D nl80211 -c wpa_supplicant-p2p0.conf
ExecStop=

[Install]
WantedBy=multi-user.target
networkimprov commented 9 years ago

I have tentatively packaged udhcp herein as well. Need input on .service code...

thomasdziedzic commented 9 years ago

With regards to udhcpd-p2p.service

  1. We could split this up even further into 2 units? One that initializes the interface, and one that initializes udhcpd
  2. I think you might be missing WantedBy=multi-user.target
  3. Is there a way to stop udhcpd in ExecStop?

For wpa_supplicant-p2p.service:

  1. We can get some things out of this example wpa_supplicant from /usr/lib/systemd/system/wpa_supplicant@.service
[Unit]
Description=WPA supplicant daemon (interface-specific version)
Requires=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

# NetworkManager users will probably want the dbus version instead.

[Service]
Type=simple
ExecStart=/usr/bin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -i%I

[Install]
Alias=multi-user.target.wants/wpa_supplicant@%i.service

Specifically the Requires, After, Type seem interesting.

  1. /var/run is a symlink to /run so you could use that instead
networkimprov commented 9 years ago

We could create a p2p0 unit, but aren't devices init'd that way usually found by the kernel? Do we gain anything with a 3rd unit? New draft...

mwifiex-p2p_wpa.service

[Unit]
Description=WiFi P2P on mwifiex driver
Wants=mwifiex-p2p_dhcp.service
After=mwifiex-p2p_dhcp.service

[Service]
Type=simple
ExecStart=/usr/bin/wpa_supplicant -i p2p0 -D nl80211 -c /etc/wpa_supplicant/wpa_supplicant-p2p0.conf

[Install]
WantedBy=multi-user.target

mwifiex-p2p_dhcp.service

[Unit]
Description=udhcpd for WiFi P2P on mwifiex driver
After=network.target

[Service]
Type=forking
PIDFile=/run/udhcpd-p2p0.pid
ExecStartPre=/bin/bash -c "\
  if ! /usr/bin/ip addr show p2p0 &> /dev/null; then \
    /usr/bin/iw phy phy0 interface add p2p0 type __p2pcl; sleep 1; \
  fi"
ExecStartPre=/usr/bin/ip addr add 192.168.3.11/24 dev p2p0
ExecStartPre=/usr/bin/ip link set p2p0 up
ExecStart=/usr/bin/udhcpd /etc/udhcpd-p2p0.conf
ExecStopPost=/usr/bin/ip link set p2p0 down
ExecStopPost=/usr/bin/ip addr flush dev p2p0

[Install]
# invoked by mwifiex-p2p_wpa.service
networkimprov commented 9 years ago

I have a package about ready. Can you review the above draft?

thomasdziedzic commented 9 years ago

This looks ok, I would say lets give it a shot with the mentioned unit files.

thomasdziedzic commented 9 years ago

My only concern is the bit with 192.168.3.11/24. If we never have to have a different ip, then this seems fine.

networkimprov commented 9 years ago

I think it's ok to leave it there. A client to the anvl needs to know this number, but we can present it to the user (if connected to usb-ethernet) via ip addr show p2p0

networkimprov commented 9 years ago

pushed package mwifiex-p2p. Its pkgbuild needs to be verified.

In rootfs... Remove files from create-rootfs & directory: . wifi-p2p_init.sh, udhcpd.conf, wpa_supplicant.conf, enable_debug.sh Replace package udhcp with mwifiex-p2p systemctl enable mwifiex-p2p_wpa systemctl enable mwifiex-p2p_dhcp