Port WPA supplicant to RTEMS-libbsd

47 篇文章 26 订阅
28 篇文章 6 订阅

上篇博文详细描述了import wpa_supplicant from FreeBSD。 这篇博客将描述如何将wpa supplicant 在RTEMS环境下编译。



1.RTEMS doesn't support the PID and daemonize, so we need modify the os_unix.c.


a). Add the unistd.h

 #include <mach/mach_time.h>
 #endif /* __MACH__ */

+#ifdef __rtems__
+#include <unistd.h>
+#endif /* __rtems__ */
+
 #include "os.h"
 #include "common.h"



b). Return -1 for os_daemonize function. We add defined(__rtems__) in os_daemonize funtion

 int os_daemonize(const char *pid_file)
 {
-#if defined(__uClinux__) || defined(__sun__)
+#if defined(__uClinux__) || defined(__sun__) || defined(__rtems__)
  return -1;
 #else /* defined(__uClinux__) || defined(__sun__) */
 #ifdef __FreeBSD__



2. RTEMS doesn't support the urandom, which is widely used in FreeBSD and Linux to generate the random number. So we need replace it with getentropy function, which is supported in RTEMS.

os_unix.c

int os_get_random(unsigned char *buf, size_t len)
{
 FILE *f;
 size_t rc;

 if (TEST_FAIL())
  return -1;

#ifdef __rtems__
    return getentropy(buf, len);
#else /* __rtems__ */
 f = fopen("/dev/urandom", "rb");
 if (f == NULL) {
  printf("Could not open /dev/urandom.\n");
  return -1;
 }

 rc = fread(buf, 1, len, f);
 fclose(f);

 return rc != len ? -1 : 0;
#endif /* __rtems__ */
}



3. Add rtems-bsd-commands.h in WPA config.h, so we can use wpa supplicant command in wpa main.c file.

 #include "wps/wps.h"
 #include "common/ieee802_11_defs.h"
 #include "common/ieee802_11_common.h"
-
+#ifdef __rtems__
+#include <machine/rtems-bsd-commands.h>
+#endif /* __rtems__ */



4. Add wpa_supplicant command function in wpa_supplicant main.c file. Because this file is the interface between OS and WPA, RTEMS control and use wpa supplicant via this file interface.

 #endif /* __linux__ */
 }

+#ifdef __rtems__
+#include <rtems/libio.h>
+
+static int
+main(int argc, char **argv);
+
+int rtems_bsd_command_wpa_supplicant(int argc, char **argv)
+{
+ int exit_code;
+
+ exit_code = rtems_bsd_program_call_main("wpa_supplicant", main, argc, argv);
+
+ return exit_code;
+}
+#endif /* __rtems__ */

 int main(int argc, char *argv[])
 {




5. Add WPA encryption algorithm module suppport in nexus-devices.h


 SYSINIT_MODULE_REFERENCE(wlan_sta);
 SYSINIT_MODULE_REFERENCE(wlan_amrr);
 SYSINIT_MODULE_REFERENCE(wlan_wep);
+SYSINIT_MODULE_REFERENCE(wlan_tkip);
+SYSINIT_MODULE_REFERENCE(wlan_ccmp);
 SYSINIT_REFERENCE(rtwn_rtl8188eufw);


WPA加密WiFi需要tkip和ccmp加密算法的支持,ccmp就是AES加密。



6. Coding the wpa supplicant shell command files: rtems-bsd-shell-wpa_supplicant.c


+/*
+ * Copyright (c) 2017 Sichen Zhao.  All rights reserved.
+ *
+ *  <zsc19940506@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <rtems/netcmds-config.h>
+#include <machine/rtems-bsd-commands.h>
+
+rtems_shell_cmd_t rtems_shell_WPA_SUPPLICANT_Command = {
+  .name = "wpa_supplicant",
+  .usage = "wpa_supplicant [args]",
+  .topic = "net",
+  .command = rtems_bsd_command_wpa_supplicant
+};



We can see from this file, in rtems_shell_WPA_SUPPLICANT_Command struct, i set the Command name: wpa_supplicant, and command function is rtems_bsd_command_wpa_supplicant. So when we use wpa_supplicant command in shell, we are go to the rtems_bsd_command_wpa_supplicant function.

从该文件可以看出,在结构体rtems_shell_WPA_SUPPLICANT_Command 中,我们设置了command的name:wpa_supplicant, command的调用函数是rtems_bsd_command_wpa_supplicant,因此当我们使用wpa_supplicant命令时,系统能够进入rtems_bsd_command_wpa_supplicant函数。


And this rtems_bsd_command_wpa_supplicant function is implemented in wpa supplicant main.c on the above.
In order to let the rtems can find where the rtems_bsd_command_wpa_supplicant funcion are. We need state this function in rtemsbsd/include/machine/rtems-bsd-commands.h

这个rtems_bsd_command_wpa_supplicant 函数在wpa_suppliacnt源码中的main.c文件中实现,为了让系统能够找到该函数的位置,我们应该在rtemsbsd/include/machine/rtems-bsd-commands.h声明该函数。

 int rtems_bsd_command_dhcpcd(int argc, char **argv);

+int rtems_bsd_command_wpa_supplicant(int argc, char **argv);
+
 int rtems_bsd_command_tcpdump(int argc, char **argv);

 int rtems_bsd_command_sysctl(int argc, char **argv);



And for the same reason, we need state rtems_shell_WPA_SUPPLICANT_Command struct in rtemsbsd/include/rtems/netcmds-config.h to help the application find where the rtems_shell_WPA_SUPPLICANT_Command struct defined.

同样,我们在rtemsbsd/include/rtems/netcmds-config.h文件中声明rtems_shell_WPA_SUPPLICANT_Command 结构体,来保证应用能够找到结构体的位置。


extern rtems_shell_cmd_t rtems_shell_TCPDUMP_Command;

+extern rtems_shell_cmd_t rtems_shell_WPA_SUPPLICANT_Command;
+
 extern rtems_shell_cmd_t rtems_shell_SYSCTL_Command;

 extern rtems_shell_cmd_t rtems_shell_VMSTAT_Command;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值