-extern char *ether_ntoa(const struct ether_addr *addr);
-
-/*
- * find the starting point of wl.o in memory
- * by reading /proc/ksyms
- */
-static inline void wlc_get_mem_offset(void)
-{
- FILE *f;
- char s[64];
-
- /* yes, i'm lazy ;) */
- f = popen("grep '\\[wl]' /proc/ksyms | sort", "r");
- if (fgets(s, 64, f) == 0)
- return;
-
- pclose(f);
-
- s[8] = 0;
- kmem_offset = strtoul(s, NULL, 16);
-
- /* sanity check */
- if (kmem_offset < 0xc0000000)
- kmem_offset = 0;
-}
-
-
-static int ptable_init(void)
-{
- glob_t globbuf;
- struct stat statbuf;
- int fd;
-
- if (ptable[0] == PTABLE_MAGIC)
- return 0;
-
- glob("/lib/modules/2.4.*/wl.o.patch", 0, NULL, &globbuf);
-
- if (globbuf.gl_pathv[0] == NULL)
- return -1;
-
- if ((fd = open(globbuf.gl_pathv[0], O_RDONLY)) < 0)
- return -1;
-
- if (fstat(fd, &statbuf) < 0)
- goto failed;
-
- if (statbuf.st_size < 512)
- goto failed;
-
- if (read(fd, ptable, 512) < 512)
- goto failed;
-
- if (ptable[0] != PTABLE_MAGIC)
- goto failed;
-
- close(fd);
-
- wlc_get_mem_offset();
- if (kmem_offset == 0)
- return -1;
-
- return 0;
-
-failed:
- close(fd);
-
- return -1;
-}
-
-static inline unsigned long wlc_kmem_read(unsigned long offset)
-{
- int fd;
- unsigned long ret;
-
- if ((fd = open("/dev/kmem", O_RDONLY )) < 0)
- return -1;
-
- lseek(fd, 0x70000000, SEEK_SET);
- lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR);
- read(fd, &ret, 4);
- close(fd);
-
- return ret;
-}
-
-static inline void wlc_kmem_write(unsigned long offset, unsigned long value)
-{
- int fd;
-
- if ((fd = open("/dev/kmem", O_WRONLY )) < 0)
- return;
-
- lseek(fd, 0x70000000, SEEK_SET);
- lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR);
- write(fd, &value, 4);
- close(fd);
-}
-
-static int wlc_patcher_getval(unsigned long key, unsigned long *val)
-{
- unsigned long *pt = &ptable[1];
- unsigned long tmp;
-
- if (ptable_init() < 0) {
- fprintf(stderr, "Could not load the ptable\n");
- return -1;
- }
-
- while (*pt != PTABLE_END) {
- if (*pt == key) {
- tmp = wlc_kmem_read(pt[1]);
-
- if (tmp == pt[2])
- *val = 0xffffffff;
- else
- *val = tmp;
-
- return 0;
- }
- pt += 3;
- }
-
- return -1;
-}
-
-static int wlc_patcher_setval(unsigned long key, unsigned long val)
-{
- unsigned long *pt = &ptable[1];
-
- if (ptable_init() < 0) {
- fprintf(stderr, "Could not load the ptable\n");
- return -1;
- }
-
- if (val != 0xffffffff)
- val = (pt[2] & ~(0xffff)) | (val & 0xffff);
-
- while (*pt != PTABLE_END) {
- if (*pt == key) {
- if (val == 0xffffffff) /* default */
- val = pt[2];
-
- wlc_kmem_write(pt[1], val);
- }
- pt += 3;
- }
-
- return 0;
-}
-
-static int wlc_slottime(wlc_param param, void *data, void *value)