@@ -4328,6 +4328,20 @@ static inline void __iccom_statistics_init(struct iccom_dev *iccom)
4328
4328
atomic_long_set (& iccom -> p -> statistics .messages_ready_in_storage , 0 );
4329
4329
}
4330
4330
4331
+ // Handles the iccom ctl channel messages. Those messages
4332
+ // include protocol negotiations messages, embedded
4333
+ // ack messages, etc..
4334
+ //
4335
+ // @channel must always be ICCOM_CTL_CHANNEL.
4336
+ // @consumer_data points to iccom_dev.
4337
+ static bool __iccom_ctl_msg_handler (unsigned int channel
4338
+ , void * msg_data , size_t msg_len
4339
+ , void * consumer_data )
4340
+ {
4341
+ // here the ctl handling logic shall be
4342
+ return false;
4343
+ }
4344
+
4331
4345
/* -------------------------- KERNEL SPACE API --------------------------*/
4332
4346
4333
4347
// API
@@ -4457,6 +4471,9 @@ int iccom_flush(struct iccom_dev *iccom)
4457
4471
// as global callback for all channels.
4458
4472
// NOTE: global callback is used only when specific channel
4459
4473
// callback is not set.
4474
+ // NOTE: the ICCOM_CTL_CHANNEL is reserved for the internal
4475
+ // ICCom communications, it will not be possible to use it
4476
+ // from outside of the ICCom.
4460
4477
// @message_ready_callback {valid ptr || NULL} the pointer to the
4461
4478
// callback which is to be called when channel gets a message
4462
4479
// ready. NULL value disables the callback function on the channel.
@@ -4488,6 +4505,12 @@ int iccom_set_channel_callback(struct iccom_dev *iccom
4488
4505
iccom_err ("broken callback pointer provided" );
4489
4506
return - EINVAL ;
4490
4507
}
4508
+ if (channel == ICCOM_CTL_CHANNEL ) {
4509
+ iccom_err ("channel %d is reserved for iccom internal ctl messages"
4510
+ " so, can not assign a custom callback to it"
4511
+ , ICCOM_CTL_CHANNEL );
4512
+ return - EINVAL ;
4513
+ }
4491
4514
4492
4515
return iccom_msg_storage_set_channel_callback (
4493
4516
& iccom -> p -> rx_messages , channel
@@ -4519,6 +4542,12 @@ int iccom_remove_channel_callback(struct iccom_dev *iccom
4519
4542
ICCOM_CHECK_XFER_DEVICE ("broken xfer device" , return - ENODEV );
4520
4543
ICCOM_CHECK_CHANNEL ("bad channel" , return - EBADSLT );
4521
4544
ICCOM_CHECK_CLOSING ("will not invoke" , return - EBADFD );
4545
+ if (channel == ICCOM_CTL_CHANNEL ) {
4546
+ iccom_err ("channel %d is reserved for iccom internal ctl messages"
4547
+ " so, can not remove it's callback"
4548
+ , ICCOM_CTL_CHANNEL );
4549
+ return - EINVAL ;
4550
+ }
4522
4551
return iccom_msg_storage_reset_channel_callback (
4523
4552
& iccom -> p -> rx_messages , channel );
4524
4553
}
@@ -4832,10 +4861,17 @@ int iccom_init(struct iccom_dev *iccom, struct platform_device *pdev)
4832
4861
goto free_private ;
4833
4862
}
4834
4863
4864
+ if (iccom_msg_storage_set_channel_callback (
4865
+ & iccom -> p -> rx_messages , ICCOM_CTL_CHANNEL
4866
+ , __iccom_ctl_msg_handler , iccom ) < 0 ) {
4867
+ iccom_err ("Could not register ctl channel clbk." );
4868
+ goto free_msg_storage ;
4869
+ }
4870
+
4835
4871
res = __iccom_init_packages_storage (iccom );
4836
4872
if (res < 0 ) {
4837
4873
iccom_err ("Could not initialize packages storage." );
4838
- goto free_msg_storage ;
4874
+ goto unregister_ctl_msgs_handler ;
4839
4875
}
4840
4876
4841
4877
iccom -> p -> last_rx_package_id = ICCOM_PACKAGE_HAVE_NOT_RECEIVED_ID ;
@@ -4884,6 +4920,9 @@ int iccom_init(struct iccom_dev *iccom, struct platform_device *pdev)
4884
4920
mutex_destroy (& iccom -> p -> sysfs_test_ch_lock );
4885
4921
free_pkg_storage :
4886
4922
__iccom_free_packages_storage (iccom );
4923
+ unregister_ctl_msgs_handler :
4924
+ iccom_msg_storage_reset_channel_callback (
4925
+ & iccom -> p -> rx_messages , ICCOM_CTL_CHANNEL );
4887
4926
free_msg_storage :
4888
4927
iccom_msg_storage_free (& iccom -> p -> rx_messages );
4889
4928
free_private :
0 commit comments