diff options
author | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2009-04-09 00:51:58 -0700 |
---|---|---|
committer | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2009-04-21 14:54:49 -0700 |
commit | 5b7ebae04ae2b085897a215450e6e17eec665d5a (patch) | |
tree | ebe0483aeb7ef07dd47956a4a4888a41e4b4adbe | |
parent | 7439e734379124894652de5ea514ac91cc38676e (diff) |
libwimaxll-i2400m: introduce i2400m_create_from_handle()
Allows creation of a i2400m object when there is an existing handle
already.
Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
-rw-r--r-- | include/wimaxll/i2400m.h | 3 | ||||
-rw-r--r-- | lib/i2400m.c | 62 |
2 files changed, 56 insertions, 9 deletions
diff --git a/include/wimaxll/i2400m.h b/include/wimaxll/i2400m.h index 04c9cc9..e50941e 100644 --- a/include/wimaxll/i2400m.h +++ b/include/wimaxll/i2400m.h @@ -39,6 +39,7 @@ #include <linux/wimax/i2400m.h> struct i2400m; +struct wimaxll_handle; /* * Callback called by i2400m_msg_to_dev() when a reply to the executed @@ -78,6 +79,8 @@ typedef void (*i2400m_report_cb)( const struct i2400m_l3l4_hdr *l3l4, size_t l3l4_size); int i2400m_create(struct i2400m **, const char *, void *, i2400m_report_cb); +int i2400m_create_from_handle(struct i2400m **, struct wimaxll_handle *, + void *, i2400m_report_cb); void i2400m_destroy(struct i2400m *); int i2400m_msg_to_dev(struct i2400m *, const struct i2400m_l3l4_hdr *, size_t, i2400m_reply_cb, void *); diff --git a/lib/i2400m.c b/lib/i2400m.c index 2abc00f..6b96f3d 100644 --- a/lib/i2400m.c +++ b/lib/i2400m.c @@ -213,6 +213,21 @@ out: } +static +void __i2400m_create(struct i2400m *i2400m, + void *priv, i2400m_report_cb report_cb) +{ + pthread_mutex_init(&i2400m->mutex, NULL); + pthread_cond_init(&i2400m->cond, NULL); + i2400m->priv = priv; + i2400m->report_cb = report_cb; + i2400m->mt_pending = I2400M_MT_INVALID; + + wimaxll_set_cb_msg_to_user( + i2400m->wmx, i2400m_msg_to_user_cb, i2400m); +} + + /** * Create a i2400m handle * @@ -246,15 +261,7 @@ int i2400m_create(struct i2400m **_i2400m, const char *ifname, result = -errno; goto error_open; } - pthread_mutex_init(&i2400m->mutex, NULL); - pthread_cond_init(&i2400m->cond, NULL); - i2400m->priv = priv; - i2400m->report_cb = report_cb; - i2400m->mt_pending = I2400M_MT_INVALID; - - wimaxll_set_cb_msg_to_user( - i2400m->wmx, i2400m_msg_to_user_cb, i2400m); - + __i2400m_create(i2400m, priv, report_cb); *_i2400m = i2400m; return 0; @@ -266,6 +273,43 @@ error_calloc: /** + * Create a i2400m handle from an existing WiMAX handle + * + * Creates a handle usable to execute commands and use the i2400m + * helpers. + * + * @param _i2400m where to store the handler value (pointer to + * the descriptor). + * + * @param wmx WiMAX handle to use + * + * @param priv Pointer that the callbacks can recover from the + * handle with i2400m_priv() + * + * @param report_cb Callback function called when a report arrives + * + * @ingroup i2400m_group + */ +int i2400m_create_from_handle(struct i2400m **_i2400m, + struct wimaxll_handle *wmx, + void *priv, i2400m_report_cb report_cb) +{ + int result = -ENOMEM; + struct i2400m *i2400m; + + i2400m = calloc(sizeof(*i2400m), 1); + if (i2400m == NULL) + goto error_calloc; + i2400m->wmx = wmx; + __i2400m_create(i2400m, priv, report_cb); + *_i2400m = i2400m; + result = 0; +error_calloc: + return result; +} + + +/** * Destroy a descriptor created with i2400m_create() * * @param i2400m Handle for an i2400m as returned by |