Let the kernel use uevents to call CRDA.
authorLuis R. Rodriguez <lrodriguez@atheros.com>
Tue, 12 Aug 2008 01:36:48 +0000 (18:36 -0700)
committerLuis R. Rodriguez <lrodriguez@atheros.com>
Tue, 12 Aug 2008 01:36:48 +0000 (18:36 -0700)
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
README
crda.c
regulatory.rules [new file with mode: 0644]

diff --git a/README b/README
index d9ba2af..440d7ec 100644 (file)
--- a/README
+++ b/README
@@ -5,14 +5,28 @@ This is the Central Regulatory Domain Agent for Linux. It serves two
 purposes: keep a database of world-wide regulatory information and
 tell the Linux kernel what to enforce.
 
- REQUIREMENTS
-==============
+ HOST REQUIREMENTS
+===================
+
+CRDA is provided as a binary file so all the host needs is libc/uclibc.
+
+ BUILD REQUIREMENTS
+====================
+
+The package build requirements currently are:
 
-The package requirements currently are:
  * python and the m2crypto package (python-m2crypto)
  * libgcrypt or libssl (openssl) header files
  * MoinMoin (http://moinmo.in) for the web viewer
 
+ CALLING CRDA -- UDEV
+======================
+
+Distributions can set up a udev rule to allow the kernel's regulatory
+domain change request to be reviewed by CRDA so CRDA can pass an
+appropriate regulatory domain. An example regulatory rule is provided
+with this package as regulatory.rules
+
  OVERVIEW
 ==========
 
diff --git a/crda.c b/crda.c
index 3a45da1..9c42b5d 100644 (file)
--- a/crda.c
+++ b/crda.c
@@ -6,6 +6,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -173,6 +174,7 @@ int main(int argc, char **argv)
        struct regdb_file_reg_country *countries;
        int dblen, siglen, num_countries, i, j, r;
        char alpha2[2];
+       char *env_country;
        struct nl80211_state nlstate;
        struct nl_cb *cb = NULL;
        struct nl_msg *msg;
@@ -197,17 +199,24 @@ int main(int argc, char **argv)
 #endif
        char *regdb = "/usr/lib/crda/regulatory.bin";
 
-       if (argc != 2) {
-               fprintf(stderr, "Usage: %s <ISO-3166 alpha2 country code>\n", argv[0]);
+       if (argc != 1) {
+               fprintf(stderr, "Usage: %s\n", argv[0]);
                return -EINVAL;
        }
+
+       env_country = getenv("COUNTRY");
+       if (!env_country) {
+               fprintf(stderr, "COUNTRY environment variable not set.\n");
+               return -EINVAL;
+       }
+
        
-       if (!is_alpha2(argv[1]) && !is_world_regdom(argv[1])) {
-               fprintf(stderr, "Invalid alpha2\n");
+       if (!is_alpha2(env_country) && !is_world_regdom(env_country)) {
+               fprintf(stderr, "Invalid alpha2 set in COUNTRY\n");
                return -EINVAL;
        }
 
-       memcpy(alpha2, argv[1], 2);
+       memcpy(alpha2, env_country, 2);
 
        r = nl80211_init(&nlstate);
        if (r)
diff --git a/regulatory.rules b/regulatory.rules
new file mode 100644 (file)
index 0000000..e81d802
--- /dev/null
@@ -0,0 +1,5 @@
+# Runs CRDA for kernel wireless regulatory events.
+# For more information see:
+# http://wireless.kernel.org/en/developers/Regulatory/CRDA
+
+KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda"