]> code.delx.au - gnu-emacs-elpa/blob - packages/enwc/enwc-cm.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / enwc / enwc-cm.el
1 ;; enwc-cm.el
2
3 ;; Copyright (C) 2012,2013 Free Software Foundation, Inc.
4
5 ;; Author: Ian Dunn
6 ;; Keywords: enwc, network, wicd, manager, nm
7
8 ;; This file is part of ENWC
9
10 ;; ENWC is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14
15 ;; ENWC is distributed in the hope that it will be useful, but WITHOUT
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 ;; License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with ENWC; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 ;; 02110-1301, USA.
24
25 ;; connect
26 ;; disconnect
27 ;; scan
28 ;; get-prop
29 ;; save-profile
30 ;; get-networks
31 ;; check-connecting
32 ;; get-current-nw-id
33
34
35 (require 'enwc)
36
37 (defgroup enwc-cm nil
38 "*ConnMan variables for ENWC"
39 :prefix "ewnc-cm-"
40 :group 'enwc)
41
42 (defcustom enwc-cm-dbus-service "net.connman"
43 "ConnMan D-Bus service."
44 :group 'enwc-cm
45 :type 'string)
46
47
48 ;; DEMAND TO SEE LIFE'S MANAGER!!
49
50 (defcustom enwc-cm-dbus-manager-interface "net.connman.Manager"
51 "ConnMan D-Bus Manager interface."
52 :group 'enwc-cm
53 :type 'string)
54
55 (defcustom enwc-cm-dbus-service-interface "net.connman.Service"
56 "ConnMan D-Bus Service interface."
57 :group 'enwc-cm
58 :type 'string)
59
60 (defvar enwc-cm-details-list
61 '("Name" "bssid" "Strength" "Security" "mode" "channel"))
62
63 (defun enwc-cm-get-services ()
64 (dbus-call-method :system
65 enwc-cm-dbus-service
66 "/"
67 enwc-cm-dbus-manager-interface
68 "GetServices"))
69
70 (defun enwc-cm-get-networks ()
71 (let ((services (enwc-cm-get-services)))
72 (mapcar 'car services)))
73
74 (defun enwc-cm-get-network (id)
75 (nth id (enwc-cm-get-services)))
76
77 ;; scan
78 (defun enwc-cm-scan (wired)
79 (dbus-call-method :system
80 enwc-cm-dbus-service
81 "/net/connman/technology/(ethernet|wifi)"
82 "net.connman.Technology"
83 "Scan"))
84
85 ;; connect
86 (defun enwc-cm-connect (wired id)
87 (dbus-call-method :system
88 enwc-cm-dbus-service
89 "/net/connman/service/serviceID"
90 enwc-cm-dbus-service-interface
91 "Connect"))
92
93
94 (defun enwc-cm-disconnect (wired)
95 (dbus-call-method :system
96 enwc-cm-dbus-service
97 "/net/connman/service/CONNECTED-SERVICE"
98 enwc-cm-dbus-service-interface
99 "Disconnect"))
100
101 (defun enwc-cm-get-nw-prop (id prop)
102 (let ((network (enwc-cm-get-network id)))
103 (car (cadr (assoc prop (cadr network))))))
104
105 (defun enwc-cm-get-wireless-network-property (id prop)
106 (enwc-cm-get-nw-prop id prop))
107
108 (defun enwc-cm-get-encryption-type (id)
109 (enwc-cm-get-nw-prop id "Security"))
110
111 (defun enwc-cm-get-ip-addr (wired id)
112 (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
113 (car (cadr (assoc "Address" ipv4-config)))))
114
115 (defun enwc-cm-get-netmask (wired id)
116 (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
117 (car (cadr (assoc "Netmask" ipv4-config)))))
118
119 (defun enwc-cm-get-gateway (wired id)
120 (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
121 (car (cadr (assoc "Gateway" ipv4-config)))))
122
123 (defun enwc-cm-get-dns (wired id)
124 (enwc-cm-get-nw-prop id "Nameservers.Configuration"))
125
126 (defun enwc-cm-set-nw-prop (wired id prop val)
127 (dbus-call-method :system
128 enwc-cm-dbus-service
129 (car (enwc-cm-get-network id))
130 enwc-cm-dbus-service-interface
131 "SetProperty"
132 prop
133 val))
134
135 (defun enwc-cm-save-nw-settings (wired id settings)
136 (let* ((ipv4 (enwc-cm-get-nw-prop id "IPv4.Configuration"))
137 (method (car (cadr (assoc "Method" ipv4))))
138 (ip-addr (cdr (assoc "addr" settings)))
139 (netmask (cdr (assoc "netmask" settings)))
140 (gateway (cdr (assoc "gateway" settings)))
141 new-ipv4-config new-dns-config)
142 (setq new-ipv4-config
143 (list (list (cons "Method" (cons (cons method nil) nil))
144 (cons "Address" (cons (cons ip-addr nil) nil))
145 (cons "Netmask" (cons (cons netmask nil) nil))
146 (cons "Gateway" (cons (cons gateway nil) nil)))))
147 (setq new-dns-config
148 (list (list (cdr (assoc "dns1" settings))
149 (cdr (assoc "dns2" settings)))))
150 (enwc-cm-set-nw-prop wired id "IPv4.Configuration"
151 new-ipv4-config)
152 (enwc-cm-set-nw-prop wired id "Nameservers.Configuration"
153 new-dns-config)))