db845c: qcom: Add userspace tools to talk to dsp and modem

Add Qcom userspace tools and their respective sepolicy rules.

Userspace tools are downloaded from following github:

To trigger loading of wlan firmware on SDM845
git clone https://github.com/andersson/pd-mapper

Userspace reference for net/qrtr in the Linux kernel
git clone https://github.com/andersson/qrtr

Qualcomm Remote Filesystem Service Implementation
git clone https://github.com/andersson/rmtfs

Trivial File Transfer Protocol server over AF_QIPCRTR
git clone https://github.com/andersson/tqftpserv

Change-Id: Ic466af6fef010a9b71c90e38205f49a876b001e2
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
diff --git a/qcom/qrtr/qrtr.py b/qcom/qrtr/qrtr.py
new file mode 100755
index 0000000..ab6189a
--- /dev/null
+++ b/qcom/qrtr/qrtr.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python2.7
+
+import ctypes
+import collections
+
+from ctypes import CDLL, CFUNCTYPE, POINTER, cast, py_object
+from ctypes import c_char_p, c_void_p, c_int, pointer
+
+_qrtr = CDLL("./libqrtr.so")
+
+class qrtr:
+    Result = collections.namedtuple('Result', ['service', 'instance', 'addr'])
+    _cbtype = CFUNCTYPE(None, c_void_p, c_int, c_int, c_int, c_int)
+    def __init__(self, port=0):
+        self.sock = _qrtr.qrtr_open(port)
+        if self.sock < 0:
+            raise RuntimeError("unable to open qrtr socket")
+        self.service = None
+        self._qrtr = _qrtr
+
+    def __del__(self):
+        self._qrtr.qrtr_close(self.sock)
+
+    def _lookup_list_add(self, ptr, srv, instance, node, port):
+        res = qrtr.Result(srv, instance, (node, port))
+        cast(ptr, POINTER(py_object)).contents.value.append(res)
+
+    def lookup(self, srv, instance=0, ifilter=0):
+        results = []
+        err = _qrtr.qrtr_lookup(self.sock, srv, instance, ifilter,
+                qrtr._cbtype(self._lookup_list_add), cast(pointer(py_object(results)), c_void_p))
+        if err:
+            raise RuntimeError("query failed")
+        return results
+
+    def publish(self, service, version, instance):
+        err = _qrtr.qrtr_publish(self.sock, service, version, instance)
+        if err:
+            raise RuntimeError("publish failed")
+        self.service = (service, version, instance)
+
+    def new_server(self, service, version, instance):
+        err = _qrtr.qrtr_new_server(self.sock, service, version, instance)
+        if err:
+            raise RuntimeError("new_server failed")
+        self.service = (service, version, instance)
+
+        return self.service
+
+    def remove_server(self, service):
+        err = _qrtr.qrtr_remove_server(self.sock, *service)
+        if err:
+            raise RuntimeError("remove_server failed")
+        self.service = None
+
+    def new_lookup(self, service, version, instance):
+        err = _qrtr.qrtr_new_lookup(self.sock, service, version, instance)
+        if err:
+            raise RuntimeError("new_lookup failed")
+        return (service, version, instance)
+
+    def remove_lookup(self, lookup):
+        err = _qrtr.qrtr_remove_lookup(self.sock, *lookup)
+        if err:
+            raise RuntimeError("remove_lookup failed")
+
+    def send(self, addr, data):
+        node, port = addr
+        n = _qrtr.qrtr_sendto(self.sock, node, port, c_char_p(data), len(data))
+        if n:
+            raise RuntimeError("sendto failed")
+
+    def recv(self, sz=65536):
+        buf = ctypes.create_string_buffer(sz)
+        n = _qrtr.qrtr_recv(self.sock, c_char_p(ctypes.addressof(buf)), sz)
+        if n <= 0:
+            raise RuntimeError("recv failed")
+        return buf[0:n]
+
+    def recvfrom(self, sz=65536):
+        node = ctypes.c_int()
+        port = ctypes.c_int()
+        buf = ctypes.create_string_buffer(sz)
+        n = _qrtr.qrtr_recvfrom(self.sock, c_char_p(ctypes.addressof(buf)),
+                ctypes.byref(node), ctypes.byref(port))
+        if n <= 0:
+            raise RuntimeError("recvfrom failed")
+        return (buf[0:n], (node.value, port.value))
+
+    def poll(self, tout=0):
+        return _qrtr.qrtr_poll(self.sock, tout)
+
+if __name__ == "__main__":
+    svcs = qrtr().lookup(15) # 15 is the test service
+    print " service  instance  addr"
+    for svc in svcs:
+        print "% 8d  % 8d  %s" % (svc.service, svc.instance, svc.addr)