[PATCH 2/7] wpaspy: add option to use wpa_cli

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This one allow connection to remote/local
host via SSH and use wpa_cli.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx>
---
 wpaspy/wpaspy.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/wpaspy/wpaspy.py b/wpaspy/wpaspy.py
index 5b8140b7c..ae305c8d5 100644
--- a/wpaspy/wpaspy.py
+++ b/wpaspy/wpaspy.py
@@ -10,16 +10,26 @@ import os
 import stat
 import socket
 import select
+import remotehost
 
 counter = 0
 
 class Ctrl:
-    def __init__(self, path, port=9877):
+    def __init__(self, path, port=9877, hostname=None, ifname=None):
         global counter
         self.started = False
         self.attached = False
         self.path = path
         self.port = port
+        self.ifname = ifname
+        self.host = None
+        self.proc = None
+        self.hostname = hostname
+
+        if hostname:
+            self.host = remotehost.Host(hostname)
+            self.started = True
+            return
 
         self.udp = False
         if not path.startswith('/'):
@@ -74,6 +84,11 @@ class Ctrl:
                 # Need to ignore this allow the socket to be closed
                 self.attached = False
                 pass
+
+        if self.host and self.started:
+            self.started = False
+            return
+
         if self.started:
             self.s.close()
             if not self.udp:
@@ -81,6 +96,15 @@ class Ctrl:
             self.started = False
 
     def request(self, cmd, timeout=10):
+        if self.host:
+            cmd = '\'' + cmd + '\''
+            if self.ifname:
+                _cmd = ['wpa_cli', '-p', self.path, '-i', self.ifname, "raw " + cmd]
+            else:
+                _cmd = ['wpa_cli', '-g', self.path, "raw " + cmd]
+            status, buf = self.host.execute(_cmd)
+            return buf
+
         if type(cmd) == str:
             try:
                 cmd2 = cmd.encode()
@@ -104,6 +128,16 @@ class Ctrl:
     def attach(self):
         if self.attached:
             return None
+
+        if self.host:
+            if self.ifname:
+                _cmd = [ "wpa_cli", "-p", self.path, "-i", self.ifname ]
+            else:
+                _cmd = [ "wpa_cli", '-g', self.path]
+            self.proc = self.host.proc_run(_cmd)
+            self.attached = True
+            return
+
         res = self.request("ATTACH")
         if "OK" in res:
             self.attached = True
@@ -113,6 +147,15 @@ class Ctrl:
     def detach(self):
         if not self.attached:
             return None
+
+        if self.hostname and self.proc:
+            self.request("DETACH")
+            self.request("QUIT")
+            self.host.proc_stop(self.proc)
+            self.attached = False
+            self.proc = None
+            return None
+
         if self.s.fileno() == -1:
             self.attached = False
             return None
@@ -135,12 +178,19 @@ class Ctrl:
         self.close()
 
     def pending(self, timeout=0):
+        if self.host and self.proc:
+            return self.host.proc_pending(self.proc, timeout=timeout)
+
         [r, w, e] = select.select([self.s], [], [], timeout)
         if r:
             return True
         return False
 
     def recv(self):
+        if self.host and self.proc:
+            res = self.host.proc_read(self.proc)
+            return res
+
         res = self.s.recv(4096).decode()
         try:
             r = str(res)
-- 
2.25.1


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux