Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * llc_station.c - station component of LLC |
| 3 | * |
| 4 | * Copyright (c) 1997 by Procom Technology, Inc. |
| 5 | * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 6 | * |
| 7 | * This program can be redistributed or modified under the terms of the |
| 8 | * GNU General Public License as published by the Free Software Foundation. |
| 9 | * This program is distributed without any warranty or implied warranty |
| 10 | * of merchantability or fitness for a particular purpose. |
| 11 | * |
| 12 | * See the GNU General Public License for more details. |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <net/llc.h> |
| 18 | #include <net/llc_sap.h> |
| 19 | #include <net/llc_conn.h> |
| 20 | #include <net/llc_c_ac.h> |
| 21 | #include <net/llc_s_ac.h> |
| 22 | #include <net/llc_c_ev.h> |
| 23 | #include <net/llc_c_st.h> |
| 24 | #include <net/llc_s_ev.h> |
| 25 | #include <net/llc_s_st.h> |
| 26 | #include <net/llc_pdu.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb) |
| 29 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); |
| 31 | |
Ben Hutchings | 025e363 | 2012-09-15 17:11:18 +0000 | [diff] [blame] | 32 | return LLC_PDU_IS_CMD(pdu) && /* command PDU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ |
| 34 | LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID && |
| 35 | !pdu->dsap ? 0 : 1; /* NULL DSAP value */ |
| 36 | } |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb) |
| 39 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); |
| 41 | |
Ben Hutchings | 025e363 | 2012-09-15 17:11:18 +0000 | [diff] [blame] | 42 | return LLC_PDU_IS_CMD(pdu) && /* command PDU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */ |
| 44 | LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST && |
| 45 | !pdu->dsap ? 0 : 1; /* NULL DSAP */ |
| 46 | } |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static int llc_station_ac_send_xid_r(struct sk_buff *skb) |
| 49 | { |
| 50 | u8 mac_da[ETH_ALEN], dsap; |
| 51 | int rc = 1; |
Joonwoo Park | f83f176 | 2008-03-31 21:02:47 -0700 | [diff] [blame] | 52 | struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, |
| 53 | sizeof(struct llc_xid_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | if (!nskb) |
| 56 | goto out; |
| 57 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | llc_pdu_decode_sa(skb, mac_da); |
| 59 | llc_pdu_decode_ssap(skb, &dsap); |
| 60 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); |
| 61 | llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127); |
Joonwoo Park | a5a0481 | 2008-03-28 16:28:36 -0700 | [diff] [blame] | 62 | rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); |
Arnaldo Carvalho de Melo | 249ff1c | 2005-09-22 04:32:10 -0300 | [diff] [blame] | 63 | if (unlikely(rc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | goto free; |
Ben Hutchings | 5ecf9ee | 2012-09-15 17:11:32 +0000 | [diff] [blame] | 65 | dev_queue_xmit(nskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | out: |
| 67 | return rc; |
| 68 | free: |
Sorin Dumitru | 91d27a8 | 2012-08-06 02:35:58 +0000 | [diff] [blame] | 69 | kfree_skb(nskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | goto out; |
| 71 | } |
| 72 | |
| 73 | static int llc_station_ac_send_test_r(struct sk_buff *skb) |
| 74 | { |
| 75 | u8 mac_da[ETH_ALEN], dsap; |
| 76 | int rc = 1; |
Joonwoo Park | f83f176 | 2008-03-31 21:02:47 -0700 | [diff] [blame] | 77 | u32 data_size; |
| 78 | struct sk_buff *nskb; |
| 79 | |
| 80 | /* The test request command is type U (llc_len = 3) */ |
| 81 | data_size = ntohs(eth_hdr(skb)->h_proto) - 3; |
| 82 | nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | if (!nskb) |
| 85 | goto out; |
| 86 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | llc_pdu_decode_sa(skb, mac_da); |
| 88 | llc_pdu_decode_ssap(skb, &dsap); |
| 89 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); |
YOSHIFUJI Hideaki | d57b186 | 2007-02-09 23:25:01 +0900 | [diff] [blame] | 90 | llc_pdu_init_as_test_rsp(nskb, skb); |
Joonwoo Park | a5a0481 | 2008-03-28 16:28:36 -0700 | [diff] [blame] | 91 | rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da); |
Arnaldo Carvalho de Melo | 249ff1c | 2005-09-22 04:32:10 -0300 | [diff] [blame] | 92 | if (unlikely(rc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | goto free; |
Ben Hutchings | 5ecf9ee | 2012-09-15 17:11:32 +0000 | [diff] [blame] | 94 | dev_queue_xmit(nskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | out: |
| 96 | return rc; |
| 97 | free: |
Sorin Dumitru | 91d27a8 | 2012-08-06 02:35:58 +0000 | [diff] [blame] | 98 | kfree_skb(nskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | goto out; |
| 100 | } |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * llc_station_rcv - send received pdu to the station state machine |
| 104 | * @skb: received frame. |
| 105 | * |
| 106 | * Sends data unit to station state machine. |
| 107 | */ |
| 108 | static void llc_station_rcv(struct sk_buff *skb) |
| 109 | { |
Ben Hutchings | 12ebc8b | 2012-09-15 17:11:47 +0000 | [diff] [blame] | 110 | if (llc_stat_ev_rx_null_dsap_xid_c(skb)) |
| 111 | llc_station_ac_send_xid_r(skb); |
| 112 | else if (llc_stat_ev_rx_null_dsap_test_c(skb)) |
| 113 | llc_station_ac_send_test_r(skb); |
Ben Hutchings | 04d191c | 2012-09-15 17:11:25 +0000 | [diff] [blame] | 114 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Ben Hutchings | 6024935 | 2012-08-13 02:49:59 +0000 | [diff] [blame] | 117 | void __init llc_station_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Ben Hutchings | aadf31d | 2012-08-13 02:50:55 +0000 | [diff] [blame] | 119 | llc_set_station_handler(llc_station_rcv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Ben Hutchings | f4f8720 | 2012-08-13 02:50:43 +0000 | [diff] [blame] | 122 | void llc_station_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | llc_set_station_handler(NULL); |
| 125 | } |