@@ -1097,48 +1097,52 @@ static bool modem_has_credentials(int sec_tag, enum modem_key_mgmt_cred_type cre
10971097 return exist ;
10981098}
10991099
1100- static void lwm2m_firware_pull_protocol_support_resource_init (int instance_id )
1100+ static void insert_supported_protocol (int instance_id , int index , uint8_t * protocol )
11011101{
1102- struct lwm2m_obj_path path ;
11031102 int ret ;
1104- int supported_protocol_count ;
1103+ struct lwm2m_obj_path path = LWM2M_OBJ (ENABLED_LWM2M_FIRMWARE_OBJECT , instance_id ,
1104+ LWM2M_FOTA_UPDATE_PROTO_SUPPORT_ID , index );
1105+ ret = lwm2m_create_res_inst (& path );
1106+ if (ret ) {
1107+ return ;
1108+ }
1109+
1110+ ret = lwm2m_set_res_buf (& path , protocol , sizeof (* protocol ), sizeof (* protocol ),
1111+ LWM2M_RES_DATA_FLAG_RO );
1112+ if (ret ) {
1113+ lwm2m_delete_res_inst (& path );
1114+ return ;
1115+ }
1116+ }
1117+
1118+ static void lwm2m_firmware_pull_protocol_support_resource_init (int instance_id )
1119+ {
1120+ int index = 0 ;
11051121
11061122 if (!IS_ENABLED (CONFIG_LWM2M_CLIENT_UTILS_ADV_FIRMWARE_UPDATE_OBJ_SUPPORT )) {
11071123 lwm2m_firmware_object_pull_protocol_init (instance_id );
11081124 }
11091125
11101126 int tag = CONFIG_LWM2M_CLIENT_UTILS_DOWNLOADER_SEC_TAG ;
1127+ bool has_ca = modem_has_credentials (tag , MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN );
1128+ bool has_psk = modem_has_credentials (tag , MODEM_KEY_MGMT_CRED_TYPE_PSK );
11111129
11121130 /* Check which protocols from pull_protocol_support[] may work.
11131131 * Order in that list is CoAP, HTTP, CoAPS, HTTPS.
11141132 * So unsecure protocols are first, those should always work.
11151133 */
11161134
1117- if (modem_has_credentials (tag , MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN )) {
1118- /* CA chain means that HTTPS and CoAPS might work, support all */
1119- supported_protocol_count = ARRAY_SIZE (pull_protocol_support );
1120- } else if (modem_has_credentials (tag , MODEM_KEY_MGMT_CRED_TYPE_PSK )) {
1121- /* PSK might work on CoAPS, not HTTPS. Drop it from the list */
1122- supported_protocol_count = ARRAY_SIZE (pull_protocol_support ) - 1 ;
1123- } else {
1124- /* Drop both secure protocols from list as we don't have credentials */
1125- supported_protocol_count = ARRAY_SIZE (pull_protocol_support ) - 2 ;
1126- }
1127-
1128- for (int i = 0 ; i < supported_protocol_count ; i ++ ) {
1129- path = LWM2M_OBJ (ENABLED_LWM2M_FIRMWARE_OBJECT , instance_id ,
1130- LWM2M_FOTA_UPDATE_PROTO_SUPPORT_ID , i );
11311135
1132- ret = lwm2m_create_res_inst (& path );
1133- if (ret ) {
1134- return ;
1136+ if (IS_ENABLED (CONFIG_DOWNLOADER_TRANSPORT_COAP )) {
1137+ insert_supported_protocol (instance_id , index ++ , & pull_protocol_support [0 ]);
1138+ if (has_ca || has_psk ) {
1139+ insert_supported_protocol (instance_id , index ++ , & pull_protocol_support [2 ]);
11351140 }
1136-
1137- ret = lwm2m_set_res_buf (& path , & pull_protocol_support [i ],
1138- sizeof (uint8_t ), sizeof (uint8_t ), LWM2M_RES_DATA_FLAG_RO );
1139- if (ret ) {
1140- lwm2m_delete_res_inst (& path );
1141- return ;
1141+ }
1142+ if (IS_ENABLED (CONFIG_DOWNLOADER_TRANSPORT_HTTP )) {
1143+ insert_supported_protocol (instance_id , index ++ , & pull_protocol_support [1 ]);
1144+ if (has_ca ) {
1145+ insert_supported_protocol (instance_id , index ++ , & pull_protocol_support [3 ]);
11421146 }
11431147 }
11441148}
@@ -1307,7 +1311,7 @@ void update_thread(void *client, void *a, void *b)
13071311static void lwm2m_firmware_object_setup_init (int object_instance )
13081312{
13091313 lwm2m_firmware_load_from_settings (object_instance );
1310- lwm2m_firware_pull_protocol_support_resource_init (object_instance );
1314+ lwm2m_firmware_pull_protocol_support_resource_init (object_instance );
13111315 lwm2m_firmware_register_write_callbacks (object_instance );
13121316}
13131317
0 commit comments