使用 C# 和 Compact Framework 管理无线网络连接

发布于 2024-07-12 06:52:37 字数 130 浏览 4 评论 0原文

标题有点概括——我需要能够以编程方式连接到已知的接入点(SSID 和凭据将在设备配置期间加载)。 我知道 Compact Framework SDK 和 OpenNETCF SDK 都提供了一些帮助方法,但我似乎找不到关于如何使用它们的好教程。

The title kinda sums it up--I need to be able to pro grammatically connect to a known access point (the SSID and credentials will be loaded during device provisioning). I understand that both the Compact Framework SDK and the OpenNETCF SDK offer some helper methods, but I can't seem to find a good tutorial on how to use them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

依 靠 2024-07-19 06:52:37

OpenNETCF 的智能设备框架可能是执行此操作的最简单机制。 无线技术面临的挑战是无线电 OEM(无论是否是设备 OEM)可以选择多种方式来宣传接口。 也许作为具有专有控件的普通 NDIS 设备(交互起来确实很痛苦),或者在另一端使用 无线零配置(WZC)。 SDF 尝试处理任何场景,根据硬件接口所宣传的内容提供越来越多的功能。

因此,如果您想使用支持 WZC 的接口添加首选网络(实际上唯一的连接方式是将该网络列入首选列表)并且该网络是开放的(不是 WEP、WPA 等),那么这是一个非常简单的任务。 事实上,WPA 甚至 TKIP 都非常简单。 您只需调用 AddPreferredNetwork 即可。 所以你会打电话 NetworkInterface.GetAllNetworkInterfaces,然后迭代结果(或使用 LINQ 进行过滤)以获取 WirelessZeroConfigNetworkInterface 类型(是的,长名称)的适配器,然后使用您的 SSID 和任何添加的信息(例如密钥材料)调用该适配器上的 AddPreferredNetwork。

当然,您也可以在没有 SDF 的情况下完成所有这些工作 - 通过 P/Invoke 所需的工作量要高得多。 但它仍然以某种形式“记录下来”。 我们所做的大部分工作是“翻译”Windows CE 中的网络对话框,它是 Platform Builder 中提供的完整源代码。

OpenNETCF's Smart Device Framework is probably the simplest mechanism to do this. The chanllenge with wireless is that the radio OEM (whether is was the device oem or not) can choose any number of ways to advertise the interface. Maybe as a plain NDIS device with proprietary controls (a real pain to interface with) or at the other end using Wireless Zero Config (WZC). The SDF tries to handle any scenario, providing more and more capability depending on what the hardware interface advertises.

So, if you want to add a preferred network using a WZC-enabled interface (really the only way to connect is for the network to be in the preferred list) and that netowork is open (not WEP, WPA, etc), it's a pretty simple task. In fact WPA and even TKIP are pretty straightforward. You simply call AddPreferredNetwork. So you'd call NetworkInterface.GetAllNetworkInterfaces, then iterate the result (or filter with LINQ) to get an adapter that is of the WirelessZeroConfigNetworkInterface type (yes, long name) and then call AddPreferredNetwork on that with your SSID and any added info like the key material.

Of course you can do all of this without the SDF as well - the amount of work required through P/Invoke is just a lot higher. But it's still all "documented" in some form. Most of what we did was a "translation" of the network dialog in Windows CE, which the full source for ships in Platform Builder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文