1# Code Organization 2At a high-level, code in this repository belongs to one of the following three 3components. 4 5## libpldm 6This is a library which deals with the encoding and decoding of PLDM messages. 7It should be possible to use this library by projects other than OpenBMC, and 8hence certain constraints apply to it: 9- keeping it light weight 10- implementation in C 11- minimal dynamic memory allocations 12- endian-safe 13- no OpenBMC specific dependencies 14 15Source files are named according to the PLDM Type, for eg base.[h/c], fru.[h/c], 16etc. 17 18Given a PLDM command "foo", the library will provide the following API: 19For the Requester function: 20``` 21encode_foo_req() - encode a foo request 22decode_foo_resp() - decode a response to foo 23``` 24For the Responder function: 25``` 26decode_foo_req() - decode a foo request 27encode_foo_resp() - encode a response to foo 28``` 29The library also provides API to pack and unpack PLDM headers. 30 31## libpldmresponder 32This library provides handlers for incoming PLDM request messages. It provides 33for a registration as well as a plug-in mechanism. The library is implemented in 34modern C++, and handles OpenBMC's platform specifics. 35 36The handlers are of the form 37``` 38Response handler(Request payload, size_t payloadLen) 39``` 40 41Source files are named according to the PLDM Type, for eg base.[hpp/cpp], 42fru.[hpp/cpp], etc. 43 44## daemon 45This is the PLDM daemon application that deals with various aspects of the 46requester and responder functions, as explained at 47https://github.com/openbmc/docs/blob/master/designs/pldm-stack.md. 48 49## TODO 50Consider hosting libpldm above in a repo of its own, probably even outside the 51OpenBMC project? A separate repo would enable something like git submodule. 52 53# Flows 54This section documents important code flow paths. 55 56## BMC as PLDM responder 57a) PLDM daemon receives PLDM request message from underlying transport (MCTP). 58 59b) PLDM daemon routes message to message handler, based on the PLDM command. 60 61c) Message handler decodes request payload into various field(s) of the request 62 message. It can make use of a decode_foo_req() API, and doesn't have to 63 perform deserialization of the request payload by itself. 64 65d) Message handler works with the request field(s) and generates response 66 field(s). 67 68e) Message handler prepares a response message. It can make use of an 69 encode_foo_resp() API, and doesn't have to perform the serialization of the 70 response field(s) by itself. 71 72f) The PLDM daemon sends the response message prepared at step e) to the remote 73 PLDM device. 74 75## BMC as PLDM requester 76a) A BMC PLDM requester app prepares a PLDM request message. There would be 77 several requester apps (based on functionality/PLDM remote device). Each of 78 them needn't bother with the serialization of request field(s), and can 79 instead make use of an encode_foo_req() API. 80 81b) BMC requester app requests PLDM daemon to send the request message to remote 82 PLDM device. 83 84c) Once the PLDM daemon receives a corresponding response message, it notifies 85 the requester app. 86 87d) The requester app has to work with the response field(s). It can make use of 88 a decode_foo_resp() API to deserialize the response message. 89