dect
/
libdect
Archived
13
0
Fork 0

lce: handle link shutdown

Notify transactions on link shutdown and clean up resources.

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2009-05-19 03:21:04 +02:00
parent 4c36389686
commit de81f2a92b
2 changed files with 25 additions and 14 deletions

View File

@ -72,7 +72,7 @@ static ssize_t dect_mbuf_rcv(const struct dect_fd *dfd, struct dect_msg_buf *mb)
mb->data = mb->head;
len = recv(dfd->fd, mb->data, sizeof(mb->head), 0);
if (len < 0) {
dect_debug("recv %Zd: %s\n", len, strerror(errno));
dect_debug("recv: %s\n", strerror(errno));
return len;
}
mb->len = len;
@ -350,6 +350,18 @@ int dect_lce_send(const struct dect_handle *dh,
}
}
static void dect_ddl_shutdown(struct dect_handle *dh,
struct dect_data_link *ddl)
{
struct dect_transaction *ta, *next;
LIST_HEAD(transactions);
ddl_debug(ddl, "shutdown");
list_splice_init(&ddl->transactions, &transactions);
list_for_each_entry_safe(ta, next, &transactions, list)
protocols[ta->pd]->shutdown(dh, ta);
}
/**
* dect_ddl_establish - Establish an outgoing data link
*
@ -547,11 +559,12 @@ static void dect_ddl_rcv_msg(struct dect_handle *dh, struct dect_data_link *ddl)
uint8_t pd, tv;
bool f;
if (dect_mbuf_rcv(ddl->dfd, mb) < 0)
return dect_ddl_shutdown(dh, ddl);
if (ddl->sdu_timer != NULL)
dect_ddl_stop_sdu_timer(dh, ddl);
if (dect_mbuf_rcv(ddl->dfd, mb) < 0)
return;
dect_mbuf_dump(mb, "RX");
if (mb->len < DECT_S_HDR_SIZE)
@ -775,16 +788,10 @@ err1:
void dect_lce_exit(struct dect_handle *dh)
{
struct dect_data_link *ddl, *ddl_next;
struct dect_transaction *ta, *ta_next;
LIST_HEAD(transactions);
struct dect_data_link *ddl, *next;
list_for_each_entry_safe(ddl, ddl_next, &dh->links, list) {
ddl_debug(ddl, "shutdown");
list_splice_init(&ddl->transactions, &transactions);
list_for_each_entry_safe(ta, ta_next, &transactions, list)
protocols[ta->pd]->shutdown(dh, ta);
}
list_for_each_entry_safe(ddl, next, &dh->links, list)
dect_ddl_shutdown(dh, ddl);
dect_unregister_fd(dh, dh->s_sap);
dect_close(dh, dh->s_sap);

View File

@ -319,7 +319,7 @@ static void dect_mm_rcv(struct dect_handle *dh, struct dect_transaction *ta,
struct dect_msg_buf *mb)
{
struct dect_mm_transaction *mmta;
mmta = container_of(ta, struct dect_mm_transaction, transaction);
switch (mb->type) {
case DECT_MM_AUTHENTICATION_REQUEST:
@ -378,7 +378,11 @@ static void dect_mm_open(struct dect_handle *dh,
static void dect_mm_shutdown(struct dect_handle *dh,
struct dect_transaction *ta)
{
dect_debug("MM: shutdown\n");
struct dect_mm_transaction *mmta;
mmta = container_of(ta, struct dect_mm_transaction, transaction);
mm_debug("MM: shutdown\n");
dect_close_transaction(dh, &mmta->transaction);
}
static const struct dect_nwk_protocol mm_protocol = {