Re: [PATCH 5/5] staging: wilc1000: use id value as argument
> Real ID value means the value mapped to an alive NIC handler. Who is mapping it? It's all within the driver so it is not "real" unless there external requirements. > And when the driver transmits and receives some data frame with chipset, > the ID is used to distinguish the data frame's owner. Just like the driver, > chipset uses the appointed identifier. the data frame always includes the > identifier. Yes. But it uses whatever we give it, otherwise it will break when we change this. > You know, current driver is using 32bit pointer address as the identifier. > So, this patch converts the address value to integer value. As mentioned > earlier, '0' value is the reserved value to terminate an alive NIC handler > and inform it to chipset. Ah... I see now. In the original code we used pointers and NULL meant disconnect. Now we are using integers but we still want zero to be disconnect. Fine, just make the array one pointer larger, it's not worth the extra headache (the first version had off by one bugs, and the second version still had an off by one bug even after I pointed them out in the first version), just to save 8 bytes: /* Zero is not used, because a zero ID means disconnect */ static tstrWILC_WFIDrv *wfidrv_list[NUM_CONCURRENT_IFC + 1]; static int add_handler_in_list(tstrWILC_WFIDrv *handler) { int i; for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { if (!wfidrv_list[i]) { wfidrv_list[i] = handler; return 0; } } return -ENOBUFS; } static int remove_handler_in_list(tstrWILC_WFIDrv *handler) { int i; for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { if (wfidrv_list[i] == handler) { wfidrv_list[i] = NULL; return 0; } } return -EINVAL; } static int get_id_from_handler(tstrWILC_WFIDrv *handler) { int i; if (!handler) return 0; for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) { if (wfidrv_list[i] == handler) return i; } return 0; } static tstrWILC_WFIDrv *get_handler_from_id(int id) { if (id <= 0 || id >= ARRAY_SIZE(wfidrv_list)) return NULL; return wfidrv_list[id]; } ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
Hello Dan. On 2015년 08월 18일 18:12, Dan Carpenter wrote: On Tue, Aug 18, 2015 at 12:10:53PM +0900, Johnny Kim wrote: Hello Dan. On 2015년 08월 13일 23:49, Dan Carpenter wrote: On Thu, Aug 13, 2015 at 01:41:23PM +0900, Tony Cho wrote: +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (wfidrv_list[id] == handler) { + id += 1; + break; + } + } + + if (id > NUM_CONCURRENT_IFC) + return 0; + else + return id; +} + This still has an off by one bug. Just use zero offset arrays throughout. static int get_id_from_handler(tstrWILC_WFIDrv *handler) { int id; if (!handler) return -ENOBUFS; for (id = 0; id < NUM_CONCURRENT_IFC; id++) { if (wfidrv_list[id] == handler) return id; } return -ENOBUFS; } Thanks for your review. The return value of this function has from 0 till 2. 1 and 2 value is real ID value. only 0 value is reserved to remove a registered id. But I also think that error handling should be added about the overflowed value as your opinion. I thought we had created "id" here in this patch so we don't have to pass function pointers through a u32 value (which can't fit a 64 bit pointer). What do you mean it is a "real ID value"? Is it there in the hardware spec? Real ID value means the value mapped to an alive NIC handler. And when the driver transmits and receives some data frame with chipset, the ID is used to distinguish the data frame's owner. Just like the driver, chipset uses the appointed identifier. the data frame always includes the identifier. You know, current driver is using 32bit pointer address as the identifier. So, this patch converts the address value to integer value. As mentioned earlier, '0' value is the reserved value to terminate an alive NIC handler and inform it to chipset. Anyway, this code is buggy and messy. Please find a different way to write it. Regards. Johnny. ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
On Tue, Aug 18, 2015 at 12:10:53PM +0900, Johnny Kim wrote: > Hello Dan. > > On 2015년 08월 13일 23:49, Dan Carpenter wrote: > >On Thu, Aug 13, 2015 at 01:41:23PM +0900, Tony Cho wrote: > >>+static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) > >>+{ > >>+ u32 id; > >>+ > >>+ if (!handler) > >>+ return 0; > >>+ > >>+ for (id = 0; id < NUM_CONCURRENT_IFC; id++) { > >>+ if (wfidrv_list[id] == handler) { > >>+ id += 1; > >>+ break; > >>+ } > >>+ } > >>+ > >>+ if (id > NUM_CONCURRENT_IFC) > >>+ return 0; > >>+ else > >>+ return id; > >>+} > >>+ > >This still has an off by one bug. Just use zero offset arrays > >throughout. > > > >static int get_id_from_handler(tstrWILC_WFIDrv *handler) > >{ > > int id; > > > > if (!handler) > > return -ENOBUFS; > > > > for (id = 0; id < NUM_CONCURRENT_IFC; id++) { > > if (wfidrv_list[id] == handler) > > return id; > > } > > > > return -ENOBUFS; > >} > Thanks for your review. The return value of this function has from 0 till 2. > 1 and 2 value is real ID value. only 0 value is reserved to remove a > registered id. > But I also think that error handling should be added about the > overflowed value > as your opinion. I thought we had created "id" here in this patch so we don't have to pass function pointers through a u32 value (which can't fit a 64 bit pointer). What do you mean it is a "real ID value"? Is it there in the hardware spec? Anyway, this code is buggy and messy. Please find a different way to write it. regards, dan carpenter ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
Hello Dan. On 2015년 08월 13일 23:49, Dan Carpenter wrote: On Thu, Aug 13, 2015 at 01:41:23PM +0900, Tony Cho wrote: +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (wfidrv_list[id] == handler) { + id += 1; + break; + } + } + + if (id > NUM_CONCURRENT_IFC) + return 0; + else + return id; +} + This still has an off by one bug. Just use zero offset arrays throughout. static int get_id_from_handler(tstrWILC_WFIDrv *handler) { int id; if (!handler) return -ENOBUFS; for (id = 0; id < NUM_CONCURRENT_IFC; id++) { if (wfidrv_list[id] == handler) return id; } return -ENOBUFS; } Thanks for your review. The return value of this function has from 0 till 2. 1 and 2 value is real ID value. only 0 value is reserved to remove a registered id. But I also think that error handling should be added about the overflowed value as your opinion. +static tstrWILC_WFIDrv *get_handler_from_id(u32 id) +{ + if (id > 0 && id <= NUM_CONCURRENT_IFC) + return wfidrv_list[id - 1]; + else + return NULL; +} static tstrWILC_WFIDrv *get_handler_from_id(int id) { if (id < 0 || id >= NUM_CONCURRENT_IFC) return NULL; return wfidrv_list[id]; } regards, dan carpenter Regards. Johnny Kim. ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
On Thu, Aug 13, 2015 at 01:41:23PM +0900, Tony Cho wrote: > +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) > +{ > + u32 id; > + > + if (!handler) > + return 0; > + > + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { > + if (wfidrv_list[id] == handler) { > + id += 1; > + break; > + } > + } > + > + if (id > NUM_CONCURRENT_IFC) > + return 0; > + else > + return id; > +} > + This still has an off by one bug. Just use zero offset arrays throughout. static int get_id_from_handler(tstrWILC_WFIDrv *handler) { int id; if (!handler) return -ENOBUFS; for (id = 0; id < NUM_CONCURRENT_IFC; id++) { if (wfidrv_list[id] == handler) return id; } return -ENOBUFS; } > +static tstrWILC_WFIDrv *get_handler_from_id(u32 id) > +{ > + if (id > 0 && id <= NUM_CONCURRENT_IFC) > + return wfidrv_list[id - 1]; > + else > + return NULL; > +} static tstrWILC_WFIDrv *get_handler_from_id(int id) { if (id < 0 || id >= NUM_CONCURRENT_IFC) return NULL; return wfidrv_list[id]; } regards, dan carpenter ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 5/5] staging: wilc1000: use id value as argument
From: Johnny Kim The driver communicates with the chipset via the address of handlers to distinguish async data frame. The SendConfigPkt function gets the pointer address indicating the handlers as the last argument, but this requires redundant typecasting and does not support the 64 bit machine. This patch adds the function which assigns ID values instead of pointer representing the driver handler to the address and then uses the ID instead of pointer as the last argument of SendConfigPkt. The driver also gets the handler's address from the ID in the data frame when it receives them. Signed-off-by: Johnny Kim Signed-off-by: Tony Cho --- drivers/staging/wilc1000/host_interface.c | 249 +++--- drivers/staging/wilc1000/host_interface.h | 1 + drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 - 3 files changed, 186 insertions(+), 65 deletions(-) diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index c4e27c7..9ffb39e 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -532,7 +532,7 @@ typedef enum { /* */ /*/ - +static tstrWILC_WFIDrv *wfidrv_list[NUM_CONCURRENT_IFC]; tstrWILC_WFIDrv *terminated_handle; tstrWILC_WFIDrv *gWFiDrvHandle; #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP @@ -592,6 +592,67 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo); extern void chip_sleep_manually(u32 u32SleepTime); extern int linux_wlan_get_num_conn_ifcs(void); +static int add_handler_in_list(tstrWILC_WFIDrv *handler) +{ + int index; + + for (index = 0; index < NUM_CONCURRENT_IFC; index++) { + if (!wfidrv_list[index]) { + wfidrv_list[index] = handler; + break; + } + } + + if (index >= NUM_CONCURRENT_IFC) + return -ENOBUFS; + + return 0; +} + +static int remove_handler_in_list(tstrWILC_WFIDrv *handler) +{ + int index; + + for (index = 0; index < NUM_CONCURRENT_IFC; index++) { + if (wfidrv_list[index] == handler) { + wfidrv_list[index] = NULL; + break; + } + } + +if (index >= NUM_CONCURRENT_IFC) +return -EINVAL; + + return 0; +} + +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (wfidrv_list[id] == handler) { + id += 1; + break; + } + } + + if (id > NUM_CONCURRENT_IFC) + return 0; + else + return id; +} + +static tstrWILC_WFIDrv *get_handler_from_id(u32 id) +{ + if (id > 0 && id <= NUM_CONCURRENT_IFC) + return wfidrv_list[id - 1]; + else + return NULL; +} /** * @brief Handle_SetChannel * @detailsSending config packet to firmware to set channel @@ -616,7 +677,8 @@ static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetChan *pst PRINT_D(HOSTINF_DBG, "Setting channel\n"); /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +get_id_from_handler(pstrWFIDrv)); if (s32Error) { PRINT_ER("Failed to set channel\n"); WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); @@ -653,7 +715,8 @@ static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +pstrHostIfSetDrvHandler->u32Address); if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) @@ -698,7 +761,8 @@ static s32 Handle_SetOperationMode(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetOpe /*Sending Cfg*/ PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p\n", pstrWFIDrv); - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +get_id_from_handler(pstrWFIDrv)); if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL) @@ -747,8 +811,8 @@ s32 Handle_set_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx) strWID.ps8WidVal = (u8 *)pu8IPAddr; strWID.s32ValueSize = IP_ALEN; - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); - + s32Error = SendC
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
On Mon, Aug 10, 2015 at 02:58:24PM +0900, Tony Cho wrote: > +static u32 add_handler_in_list(tstrWILC_WFIDrv *handler) I am suspicous of code which uses u32 for something where the hardware doesn't specify unsigned 32 bits. Why not just return "int"? > +{ > + u32 id; It looks like we have a case of u32 disease. Prefer int over u32 unless there is a reason for it. > + > + if (!handler) > + return 0; Don't add NULL checks unless it makes sense. How are we supposed to recover from this if handler is NULL? > + > + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { > + if (!wfidrv_list[id]) { > + wfidrv_list[id++] = handler; Ugh... I don't like the ++ here. Just use a zero offset array or we are going to have off by one bugs. > + break; > + } > + } > + > + if (id > NUM_CONCURRENT_IFC) > + return 0; Well, that didn't take long, it's three lines later and we already have hit our first off by one bug. This check can never be true. Of course, no one checks the return value either... > + > + return id; > +} I guess I would be fine with this patch if you changed it to use a zero offset array, ints instead of u32s and added some error handling. regards, dan carpenter ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
Hello Julian. On 2015년 08월 10일 15:47, Julian Calaby wrote: Hi Tony and Johnny, On Mon, Aug 10, 2015 at 3:58 PM, Tony Cho wrote: From: Johnny Kim The driver communicates with the chipset via the address of handlers to distinguish async data frame. The SendConfigPkt function gets the pointer address indicating the handlers as the last argument, but this requires redundant typecasting and does not support the 64 bit machine. This patch adds the function which assigns ID values instead of pointer representing the driver handler to the address and then uses the ID instead of pointer as the last argument of SendConfigPkt. The driver also gets the handler's address from the ID in the data frame when it receives them. Excellent work! A couple of minor questions: diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index c4e27c7..5a0277f 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -616,7 +680,8 @@ static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetChan *pst PRINT_D(HOSTINF_DBG, "Setting channel\n"); /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = (SET_CFG, &strWID, 1, true, +get_id_from_handler(pstrWFIDrv)); Would it make sense to call get_id_from_handler() inside SendConfigPkt() instead? SendConfigPkt function can't be aware of tstrWILC_WFIDrv type because SendConfigPkt is defined before tstrWILC_WFIDrv. if (s32Error) { PRINT_ER("Failed to set channel\n"); WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); @@ -653,7 +718,8 @@ static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true,host_int_set_wfi_drv_handler +pstrHostIfSetDrvHandler->u32Address); Is this correct? pstrHostIfSetDrvHandler->u32Address value which is input as argument isn't pointer address but ID value. The value was filled in host_int_set_wfi_drv_handler function. if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) @@ -6772,11 +6888,11 @@ void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length) { s32 s32Error = WILC_SUCCESS; tstrHostIFmsg strHostIFmsg; - u32 drvHandler; + u32 id; tstrWILC_WFIDrv *pstrWFIDrv = NULL; - drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); - pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; + id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); Would be32_to_cpu() or something like that be able to help you do this? Thank for your comment. I will fix it on another subject. + pstrWFIDrv = get_handler_from_id(id); Thanks, ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 5/5] staging: wilc1000: use id value as argument
Hi Tony and Johnny, On Mon, Aug 10, 2015 at 3:58 PM, Tony Cho wrote: > From: Johnny Kim > > The driver communicates with the chipset via the address of handlers > to distinguish async data frame. The SendConfigPkt function gets the > pointer address indicating the handlers as the last argument, but this > requires redundant typecasting and does not support the 64 bit machine. > > This patch adds the function which assigns ID values instead of pointer > representing the driver handler to the address and then uses the ID > instead of pointer as the last argument of SendConfigPkt. The driver > also gets the handler's address from the ID in the data frame when it > receives them. Excellent work! A couple of minor questions: > diff --git a/drivers/staging/wilc1000/host_interface.c > b/drivers/staging/wilc1000/host_interface.c > index c4e27c7..5a0277f 100644 > --- a/drivers/staging/wilc1000/host_interface.c > +++ b/drivers/staging/wilc1000/host_interface.c > @@ -616,7 +680,8 @@ static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, > tstrHostIFSetChan *pst > > PRINT_D(HOSTINF_DBG, "Setting channel\n"); > /*Sending Cfg*/ > - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); > + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, > +get_id_from_handler(pstrWFIDrv)); Would it make sense to call get_id_from_handler() inside SendConfigPkt() instead? > if (s32Error) { > PRINT_ER("Failed to set channel\n"); > WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); > @@ -653,7 +718,8 @@ static s32 > Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand > > /*Sending Cfg*/ > > - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); > + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, > +pstrHostIfSetDrvHandler->u32Address); Is this correct? > > > if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) > @@ -6772,11 +6888,11 @@ void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length) > { > s32 s32Error = WILC_SUCCESS; > tstrHostIFmsg strHostIFmsg; > - u32 drvHandler; > + u32 id; > tstrWILC_WFIDrv *pstrWFIDrv = NULL; > > - drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] > << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); > - pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler; > + id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | > (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24)); Would be32_to_cpu() or something like that be able to help you do this? > + pstrWFIDrv = get_handler_from_id(id); > > > Thanks, -- Julian Calaby Email: julian.cal...@gmail.com Profile: http://www.google.com/profiles/julian.calaby/ ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 5/5] staging: wilc1000: use id value as argument
From: Johnny Kim The driver communicates with the chipset via the address of handlers to distinguish async data frame. The SendConfigPkt function gets the pointer address indicating the handlers as the last argument, but this requires redundant typecasting and does not support the 64 bit machine. This patch adds the function which assigns ID values instead of pointer representing the driver handler to the address and then uses the ID instead of pointer as the last argument of SendConfigPkt. The driver also gets the handler's address from the ID in the data frame when it receives them. Signed-off-by: Johnny Kim Signed-off-by: Tony Cho --- drivers/staging/wilc1000/host_interface.c | 242 +++--- drivers/staging/wilc1000/host_interface.h | 1 + drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 - 3 files changed, 180 insertions(+), 64 deletions(-) diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index c4e27c7..5a0277f 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -532,7 +532,7 @@ typedef enum { /* */ /*/ - +static tstrWILC_WFIDrv *wfidrv_list[NUM_CONCURRENT_IFC]; tstrWILC_WFIDrv *terminated_handle; tstrWILC_WFIDrv *gWFiDrvHandle; #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP @@ -592,6 +592,70 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo); extern void chip_sleep_manually(u32 u32SleepTime); extern int linux_wlan_get_num_conn_ifcs(void); +static u32 add_handler_in_list(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (!wfidrv_list[id]) { + wfidrv_list[id++] = handler; + break; + } + } + + if (id > NUM_CONCURRENT_IFC) + return 0; + + return id; +} + +static u32 remove_handler_in_list(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (wfidrv_list[id] == handler) { + wfidrv_list[id++] = NULL; + break; + } + } + + return id; +} + +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler) +{ + u32 id; + + if (!handler) + return 0; + + for (id = 0; id < NUM_CONCURRENT_IFC; id++) { + if (wfidrv_list[id] == handler) { + id += 1; + break; + } + } + + if (id > NUM_CONCURRENT_IFC) + return 0; + else + return id; +} + +static tstrWILC_WFIDrv *get_handler_from_id(u32 id) +{ + if (id > 0 && id <= NUM_CONCURRENT_IFC) + return wfidrv_list[id - 1]; + else + return NULL; +} /** * @brief Handle_SetChannel * @detailsSending config packet to firmware to set channel @@ -616,7 +680,8 @@ static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetChan *pst PRINT_D(HOSTINF_DBG, "Setting channel\n"); /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +get_id_from_handler(pstrWFIDrv)); if (s32Error) { PRINT_ER("Failed to set channel\n"); WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE); @@ -653,7 +718,8 @@ static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHand /*Sending Cfg*/ - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +pstrHostIfSetDrvHandler->u32Address); if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) @@ -698,7 +764,8 @@ static s32 Handle_SetOperationMode(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetOpe /*Sending Cfg*/ PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p\n", pstrWFIDrv); - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); + s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, +get_id_from_handler(pstrWFIDrv)); if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL) @@ -747,8 +814,8 @@ s32 Handle_set_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx) strWID.ps8WidVal = (u8 *)pu8IPAddr; strWID.s32ValueSize = IP_ALEN; - s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv); - + s32Error = SendConfigPkt(SET_CFG,