TI did provide an answer to the solution, finally. Now I must test it. They accept to store the same device multiple times in the device table, with their unique keys and frame counter etc. I find the documentation hard to understand, and it requires a lot of research...
Actually no, that is not the scenario I was thinking about. However, it is a good point, since the sensor may be factory reset by the end user (not an ordinary thing to do, but it should still be able to connect and work again by doing the initial authorizing procedure - again!). The gateway will not accept normal data frames when factory key is used (dropped in application layer). The factory key is just used when the user authorizes the sensor for the first time with the gateway. This key is to prevent third party sensors to function with my gateway. I understand your frame counter issue, good point. The gateway has already stored the current frame counter value, and expects a higher value etc... The solution could be that the factory AES key does not implement frame counter security. Then when authorization is happening, the gateway will check if there is a record in the device table for this sensor, and if so it will delete it and store it again as a fresh sensor. When the network key has been delivered to the sensor, both the gateway and sensor can delete the factory key in their device tables for this device, since this key will no longer be used for this particular sensor.
The gateway will receive the network key from server. This way multiple gateways belonging to the customer can have the same key, and a sensor can connect to any of them. The authorization procedure would be like this (maybe): The sensor turns on and will connect to gateway (factory key), provided that customer allows this (button in web GUI). This device shows up on web/app as an unauthorized device. The customer presses a button on the sensor. The web GUI highlights the specific device (after all, many sensors could be present in GUI if the customer has turned on many sensors). The customer names the sensor in GUI. When naming is done, the sensor turns on a LED etc to inform that its done (network key transferred). The possible problem here is that another "criminal" could also have turned on a sensor of his own and pressed the button on his own sensor. The customer would then see 2 highlighted sensors appear in GUI. So the GUI should not allow authorization when more than just one sensor is highlighted, perhaps... Another fact is that when naming is done, the customer would not notice the LED-done if a criminal was trying to authorize his sensor. But the customer would then have to pay attention to this. But if the sensor is not "green" and still provides data, he should be a bit suspicious?! Another solution is to use very low transmitter power (or only accept high rssi) while in this process, in order to stop criminals with their sensor outside the close vicinity of the gateway. However, the customer may like to authorize sensors far away from the gateway... If you have any inputs to this authorization procedure, please let me know!