Please refer to the Cy_BLE_GAPP_UpdateAdvScanData() API in the BLE component datasheet. This function is used by GAP Peripheral application to set Advertisement and/or Scan Response data. This function can be used during active advertisement as well. Application should ensure the validity of the data content. On completion of this operation, GAP Peripheral application receives CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE event.
From my perspective I never would have guessed by the name of the function that it could also modify the advertising data. The documentation could be a lot more clear.
Now, the next problem is getting access to the advertising packet byte array that was assembled statically. First how can it be accessed and second, how is it put into the cy_stc_ble_gapp_disc_mode_info_t structure needed by the UpdateAdvScanData function?
I found a solution not even needing Cy_BLE_GAPP_UpdateAdvScanData().
The advertising packet bytes are at cy_ble_config.discoveryModeInfo[cy_ble_advIndex].advData as a byte array. For my application only 2 bytes need to be dynamically variable. So, just setting the bytes in this array seems to be working fine. The structure of the advertising message does not have to be changed.