From 80703b667bbf8e23298e9d6bded3ef3250986cc9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 13 Sep 2019 10:02:32 +0200 Subject: [PATCH] broadband-bearer: fix logic looking for unused CID When looking for the first unused CID, we should also consider those contexts defined with a different PDP type, not just the ones with the same PDP type. --- src/mm-broadband-bearer.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index d93fa529..d91cee90 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -892,22 +892,23 @@ parse_pdp_list (MMBaseModem *modem, break; } - /* If an unused CID was not found yet and the previous CID is not (CID - 1), - * this means that (previous CID + 1) is an unused CID that can be used. - * This logic will allow us using unused CIDs that are available in the gaps - * between already defined contexts. - */ - if (!unused_cid && prev_cid && ((prev_cid + 1) < pdp->cid)) { - unused_cid = prev_cid + 1; - mm_dbg ("Found the first unused PDP context with CID %u", unused_cid); - } /* PDP with no APN set? we may use that one if no exact match found */ - else if ((!pdp->apn || !pdp->apn[0]) && !ctx->blank_cid) { + if ((!pdp->apn || !pdp->apn[0]) && !ctx->blank_cid) { ctx->blank_cid = pdp->cid; mm_dbg ("Found the first PDP context with no APN with CID %u", ctx->blank_cid); } } + /* If an unused CID was not found yet and the previous CID is not (CID - 1), + * this means that (previous CID + 1) is an unused CID that can be used. + * This logic will allow us using unused CIDs that are available in the gaps + * between already defined contexts. + */ + if (!unused_cid && prev_cid && ((prev_cid + 1) < pdp->cid)) { + unused_cid = prev_cid + 1; + mm_dbg ("Found the first unused PDP context with CID %u", unused_cid); + } + /* Update previous CID value to the current CID for use in the next loop, * unless an unused CID was already found. */