int send_and_recv_wrapper(struct nl_cb *nl_cb, struct nl_handle *nl_handle, struct nl_msg *msg, int (*valid_handler)(struct nl_msg *, void *), void *valid_data) { struct nl_cb *cb; int err = -ENOMEM; cb = nl_cb_clone(nl_cb); if (!cb) goto out; err = nl_send_wrapper(nl_handle, msg); if (err < 0) goto out; err = 1; nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); if (valid_handler) nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, valid_handler, valid_data); while (err > 0) nl_recv_wrapper(nl_handle, cb); out: nl_cb_put(cb); nlmsg_free(msg); return err; }
static void nl80211_event_receive(int sock, void *eloop_ctx, void *handle) { struct nl_cb *cb = eloop_ctx; wpa_printf(MSG_DEBUG, "nl80211: Event message available"); nl_recv_wrapper(handle, cb); }