> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/ieee80211_output.9.md).

# ieee80211\_output.9

`ieee80211_output` — 软件 802.11 栈输出函数

## 名称

`ieee80211_output`

## 概要

```c
#include <net80211/ieee80211_var.h>
```

```c
int
M_WME_GETAC(struct mbuf *)

int
M_SEQNO_GET(struct mbuf *)

struct ieee80211_key *
ieee80211_crypto_encap(struct ieee80211_node *, struct mbuf *)

void
ieee80211_process_callback(struct ieee80211_node *, struct mbuf *, int)
```

## 描述

支持 802.11 设备驱动程序的 `net80211` 层处理传输帧所需的大部分工作。驱动程序通常接收已分类并分配传输优先级的完全封装的 802.11 帧；剩下的只是进行加密封装、准备任何硬件特定状态，并将数据包推送到设备。出站帧要么由 `net80211` 层生成（例如管理帧），要么通过 [ifnet(9)](/man/man9/ifnet.9.md) 传输队列从上层传递下来。为传输传递下来的数据帧流经 `net80211`，后者处理聚合、802.11 封装，然后通过其传输队列将帧调度到驱动程序。

帧到达驱动程序进行传输有两条控制路径。数据包排队到设备的 `if_snd` 队列，并调用驱动程序的 `if_start` 方法。其他帧使用 `ic_raw_xmit` 方法传递而不排队（除非由驱动程序完成）。原始传输路径可能包括通过 [bpf(4)](/man/man4/bpf.4.md) 注入的用户应用程序数据帧和 `net80211` 生成的用于探测空闲站的 NullData 帧（当作为接入点操作时）。

`net80211` 处理数据帧处理的所有状态相关簿记和管理。数据帧仅为处于 `IEEE80211_S_RUN` 状态的 vap 传输；例如，不需要检查 CAC 或 CSA 活动时发送的帧。同样，`net80211` 处理后台扫描和省电模式等活动，除非在 BSS 信道上以"全功率"操作，否则不会向驱动程序发送帧。

所有传递给驱动程序进行传输的帧在 `m_pkthdr.rcvif` 字段中持有节点表条目的引用。该节点与帧目标关联。通常是接收方的条目，但在某些情况下可能是占位符条目或"下一跳站"（如在 mesh 网络中）。在所有情况下，传输工作完成时必须使用 `ieee80211_free_node` 回收引用。要记住的规则是：`net80211` 将 `mbuf` 和"节点引用"的责任连同每个交给驱动程序传输的帧一起传递。

## 数据包分类

`net80211` 传输的所有帧都根据分配给接收站的任何 vlan 标签和/或 IP 或 IPv6 头中的任何 Diffserv 设置分配优先级。如果 vlan 和 Diffserv 优先级都存在，则使用两者中较高的。如果使用 WME/WMM，则（在站模式下）还会强制执行任何 ACM 策略。生成的 AC 附加到 mbuf，可以使用 `M_WME_GETAC` 宏读回。

PAE/EAPOL 帧用 `M_EAPOL` mbuf 标志标记；驱动程序应谨慎传输它们，通常使用管理帧的传输速率。多播/广播帧用 `M_MCAST` mbuf 标志标记。从站省电队列出来且紧随其后有更多帧的帧用 `M_MORE_DATA` mbuf 标志标记。此类帧将在驱动程序的 `if_snd` 队列中连续排队，驱动程序在将它们传递给设备时应保持顺序。

## 分片帧

如果驱动程序标记了 `IEEE80211_C_TXFRAG` 能力，`net80211` 层将根据 `iv_fragthreshold` 的设置对数据帧进行分片。分片帧放置在设备传输队列中，分片通过 `m_nextpkt` 链接在一起。每个帧用 `M_FRAG` mbuf 标志标记，第一个和最后一个分别用 `M_FIRSTFRAG` 和 `M_LASTFRAG` 标记。驱动程序应处理所有分片或不处理任何分片。

## 传输回调

`net80211` 发送的帧可以用 `M_TXCB` mbuf 标志标记，以指示在其传输完成时应执行回调。回调使用 `ieee80211_process_callback` 完成，最后一个参数在发生错误时设置为非零值，否则为零。注意，`net80211` 理解驱动程序可能无法确定状态；设备可能不报告是否收到 ACK 帧和/或设备可能在其硬件中排队传输请求，仅报告帧是否成功排队的状态。

## 参见

[bpf(4)](/man/man4/bpf.4.md), [ieee80211(9)](/man/man9/ieee80211.9.md), [ifnet(9)](/man/man9/ifnet.9.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/ieee80211_output.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
