diff options
Diffstat (limited to 'net/nfc/netlink.c')
-rw-r--r-- | net/nfc/netlink.c | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c index 6404052d6c07..f1829f6ae9c5 100644 --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c | |||
@@ -63,19 +63,23 @@ static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target, | |||
63 | 63 | ||
64 | genl_dump_check_consistent(cb, hdr, &nfc_genl_family); | 64 | genl_dump_check_consistent(cb, hdr, &nfc_genl_family); |
65 | 65 | ||
66 | NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target->idx); | 66 | if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) || |
67 | NLA_PUT_U32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols); | 67 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) || |
68 | NLA_PUT_U16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res); | 68 | nla_put_u16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res) || |
69 | NLA_PUT_U8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res); | 69 | nla_put_u8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res)) |
70 | if (target->nfcid1_len > 0) | 70 | goto nla_put_failure; |
71 | NLA_PUT(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len, | 71 | if (target->nfcid1_len > 0 && |
72 | target->nfcid1); | 72 | nla_put(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len, |
73 | if (target->sensb_res_len > 0) | 73 | target->nfcid1)) |
74 | NLA_PUT(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len, | 74 | goto nla_put_failure; |
75 | target->sensb_res); | 75 | if (target->sensb_res_len > 0 && |
76 | if (target->sensf_res_len > 0) | 76 | nla_put(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len, |
77 | NLA_PUT(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len, | 77 | target->sensb_res)) |
78 | target->sensf_res); | 78 | goto nla_put_failure; |
79 | if (target->sensf_res_len > 0 && | ||
80 | nla_put(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len, | ||
81 | target->sensf_res)) | ||
82 | goto nla_put_failure; | ||
79 | 83 | ||
80 | return genlmsg_end(msg, hdr); | 84 | return genlmsg_end(msg, hdr); |
81 | 85 | ||
@@ -170,7 +174,8 @@ int nfc_genl_targets_found(struct nfc_dev *dev) | |||
170 | if (!hdr) | 174 | if (!hdr) |
171 | goto free_msg; | 175 | goto free_msg; |
172 | 176 | ||
173 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 177 | if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx)) |
178 | goto nla_put_failure; | ||
174 | 179 | ||
175 | genlmsg_end(msg, hdr); | 180 | genlmsg_end(msg, hdr); |
176 | 181 | ||
@@ -183,6 +188,37 @@ free_msg: | |||
183 | return -EMSGSIZE; | 188 | return -EMSGSIZE; |
184 | } | 189 | } |
185 | 190 | ||
191 | int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx) | ||
192 | { | ||
193 | struct sk_buff *msg; | ||
194 | void *hdr; | ||
195 | |||
196 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
197 | if (!msg) | ||
198 | return -ENOMEM; | ||
199 | |||
200 | hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, | ||
201 | NFC_EVENT_TARGET_LOST); | ||
202 | if (!hdr) | ||
203 | goto free_msg; | ||
204 | |||
205 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || | ||
206 | nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx)) | ||
207 | goto nla_put_failure; | ||
208 | |||
209 | genlmsg_end(msg, hdr); | ||
210 | |||
211 | genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL); | ||
212 | |||
213 | return 0; | ||
214 | |||
215 | nla_put_failure: | ||
216 | genlmsg_cancel(msg, hdr); | ||
217 | free_msg: | ||
218 | nlmsg_free(msg); | ||
219 | return -EMSGSIZE; | ||
220 | } | ||
221 | |||
186 | int nfc_genl_device_added(struct nfc_dev *dev) | 222 | int nfc_genl_device_added(struct nfc_dev *dev) |
187 | { | 223 | { |
188 | struct sk_buff *msg; | 224 | struct sk_buff *msg; |
@@ -197,10 +233,11 @@ int nfc_genl_device_added(struct nfc_dev *dev) | |||
197 | if (!hdr) | 233 | if (!hdr) |
198 | goto free_msg; | 234 | goto free_msg; |
199 | 235 | ||
200 | NLA_PUT_STRING(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)); | 236 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || |
201 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 237 | nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || |
202 | NLA_PUT_U32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols); | 238 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || |
203 | NLA_PUT_U8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up); | 239 | nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up)) |
240 | goto nla_put_failure; | ||
204 | 241 | ||
205 | genlmsg_end(msg, hdr); | 242 | genlmsg_end(msg, hdr); |
206 | 243 | ||
@@ -229,7 +266,8 @@ int nfc_genl_device_removed(struct nfc_dev *dev) | |||
229 | if (!hdr) | 266 | if (!hdr) |
230 | goto free_msg; | 267 | goto free_msg; |
231 | 268 | ||
232 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 269 | if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx)) |
270 | goto nla_put_failure; | ||
233 | 271 | ||
234 | genlmsg_end(msg, hdr); | 272 | genlmsg_end(msg, hdr); |
235 | 273 | ||
@@ -259,10 +297,11 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev, | |||
259 | if (cb) | 297 | if (cb) |
260 | genl_dump_check_consistent(cb, hdr, &nfc_genl_family); | 298 | genl_dump_check_consistent(cb, hdr, &nfc_genl_family); |
261 | 299 | ||
262 | NLA_PUT_STRING(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)); | 300 | if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) || |
263 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 301 | nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || |
264 | NLA_PUT_U32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols); | 302 | nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) || |
265 | NLA_PUT_U8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up); | 303 | nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up)) |
304 | goto nla_put_failure; | ||
266 | 305 | ||
267 | return genlmsg_end(msg, hdr); | 306 | return genlmsg_end(msg, hdr); |
268 | 307 | ||
@@ -339,11 +378,14 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx, | |||
339 | if (!hdr) | 378 | if (!hdr) |
340 | goto free_msg; | 379 | goto free_msg; |
341 | 380 | ||
342 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 381 | if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx)) |
343 | if (rf_mode == NFC_RF_INITIATOR) | 382 | goto nla_put_failure; |
344 | NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target_idx); | 383 | if (rf_mode == NFC_RF_INITIATOR && |
345 | NLA_PUT_U8(msg, NFC_ATTR_COMM_MODE, comm_mode); | 384 | nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx)) |
346 | NLA_PUT_U8(msg, NFC_ATTR_RF_MODE, rf_mode); | 385 | goto nla_put_failure; |
386 | if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) || | ||
387 | nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode)) | ||
388 | goto nla_put_failure; | ||
347 | 389 | ||
348 | genlmsg_end(msg, hdr); | 390 | genlmsg_end(msg, hdr); |
349 | 391 | ||
@@ -376,7 +418,8 @@ int nfc_genl_dep_link_down_event(struct nfc_dev *dev) | |||
376 | if (!hdr) | 418 | if (!hdr) |
377 | goto free_msg; | 419 | goto free_msg; |
378 | 420 | ||
379 | NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx); | 421 | if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx)) |
422 | goto nla_put_failure; | ||
380 | 423 | ||
381 | genlmsg_end(msg, hdr); | 424 | genlmsg_end(msg, hdr); |
382 | 425 | ||