A communication apparatus comprising: discrimination means adapted to detect another communication apparatus and discriminate a function thereof with respect to a communication parameters setting procedure; setting means (S304, S315) adapted to set a function of the communication apparatus with respect to the communication parameters setting procedure; and execution means (S321, S319) adapted to execute the communication parameters setting procedure by exchanging predetermined messages between a providing apparatus of communication parameters and a receiving apparatus of communication parameters to enable the providing and receiving apparatuses to communicate with each other in a network; wherein i) in case that the communication apparatus detects a providing apparatus within a predetermined period while the communication apparatus is not a providing apparatus, the execution means executes, (S314, S321) as the receiving apparatus, the communication parameters setting procedure with the detected providing apparatus for receiving a communication parameters set from the detected providing apparatus, ii) otherwise, in case that the communication apparatus detects a receiving apparatus while the communication apparatus is not a receiving apparatus, the execution means executes, (S315, S319) as the providing apparatus, the communication parameters setting procedure with the detected receiving apparatus for providing a communication parameters set to the detected receiving apparatus, wherein the communication parameters set comprises at least one of an encryption scheme, an encryption key, authentication scheme, and an authentication key. discrimination means adapted to detect another communication apparatus and discriminate a function thereof with respect to a communication parameters setting procedure; setting means (S304, S315) adapted to set a function of the communication apparatus with respect to the communication parameters setting procedure; and execution means (S321, S319) adapted to execute the communication parameters setting procedure by exchanging predetermined messages between a providing apparatus of communication parameters and a receiving apparatus of communication parameters to enable the providing and receiving apparatuses to communicate with each other in a network; wherein i) in case that the communication apparatus detects a providing apparatus within a predetermined period while the communication apparatus is not a providing apparatus, the execution means executes, (S314, S321) as the receiving apparatus, the communication parameters setting procedure with the detected providing apparatus for receiving a communication parameters set from the detected providing apparatus, ii) otherwise, in case that the communication apparatus detects a receiving apparatus while the communication apparatus is not a receiving apparatus, the execution means executes, (S315, S319) as the providing apparatus, the communication parameters setting procedure with the detected receiving apparatus for providing a communication parameters set to the detected receiving apparatus, i) in case that the communication apparatus detects a providing apparatus within a predetermined period while the communication apparatus is not a providing apparatus, the execution means executes, (S314, S321) as the receiving apparatus, the communication parameters setting procedure with the detected providing apparatus for receiving a communication parameters set from the detected providing apparatus, ii) otherwise, in case that the communication apparatus detects a receiving apparatus while the communication apparatus is not a receiving apparatus, the execution means executes, (S315, S319) as the providing apparatus, the communication parameters setting procedure with the detected receiving apparatus for providing a communication parameters set to the detected receiving apparatus, wherein the communication parameters set comprises at least one of an encryption scheme, an encryption key, authentication scheme, and an authentication key.